Q:

Write a Python program to extract the nth element from a given list of tuples

0

Write a Python program to extract the nth element from a given list of tuples. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def extract_nth_element(test_list, n):
    result = [x[n] for x in test_list]
    return result

students = [('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] 
print ("Original list:")
print(students)
n = 0
print("\nExtract nth element ( n =",n,") from the said list of tuples:")
print(extract_nth_element(students, n))

n = 2
print("\nExtract nth element ( n =",n,") from the said list of tuples:")
print(extract_nth_element(students, n))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now