How to find an element in a list of tuples which has a value at a given position in Python

Finding an element in a list of tuples which has a value at a given position gets the index of the tuple which contains the specified value at the specified position. For example, in [(“a”, “b”), (“c”, “a”)], finding the tuple with value “b” at position 1 results in 0.

Solution for How to find an element in a list of tuples which has a value at a given position in Python : You can use map() to find a tuple with the desired value and position Call map(func, iterables) with func as a function which returns True only if a tuple contains the specified value at the specified position and iterables as a list of tuples. Convert the resulting map object to a list using list(iterable) to get a list of booleans. Call list.index(value) with list as the previous result and value as True to return the index of the first True in list. Print the result.


how-to-find-an-element-in-a-list-of-tuples-which-has-a-value-at-a-given-position-in-python