0 out of 464 challenges solved
Write a function `extract_nth_element` that takes a list of tuples and an integer `n` as input and returns a list containing the nth element from each tuple in the list. #### Example Usage ```python [main.nopy] # Input list of tuples input_list = [ ('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98) ] # Extract the 0th element from each tuple print(extract_nth_element(input_list, 0)) # Output: ['Greyson Fulton', 'Brady Kent', 'Wyatt Knott', 'Beau Turnbull'] # Extract the 2nd element from each tuple print(extract_nth_element(input_list, 2)) # Output: [99, 96, 94, 98] # Extract the 1st element from each tuple print(extract_nth_element(input_list, 1)) # Output: [98, 97, 91, 94] ``` #### Constraints - Assume all tuples in the list have at least `n+1` elements. - The input list can be empty, in which case the function should return an empty list.
def extract_nth_element(list_of_tuples, n): """ Extract the nth element from each tuple in the list. Args: list_of_tuples (list): A list of tuples. n (int): The index of the element to extract from each tuple. Returns: list: A list containing the nth element from each tuple. """ # Placeholder for the solution pass