I have a list of tuples: a = [(1,2),(1,4),(1,2),(6,7),(2,9)] I want to check if one of the individual elements of each tuple matches the same position/element i
a = [(1,2),(1,4),(1,2),(6,7),(2,9)]
You can make count_map, and store the count of each tuple as the value.
>>> count_map = {} >>> for t in a: ... count_map[t] = count_map.get(t, 0) +1 ... >>> count_map {(1, 2): 2, (6, 7): 1, (2, 9): 1, (1, 4): 1}