Try this using a list of concepts - this is a pythonic way to solve the problem:
lst = [(4,1), (5,1), (3,2), (7,1), (6,0)] [(x, y) for x, y in lst if y == 1] => [(4, 1), (5, 1), (7, 1)]
Notice how we use the tuple x, y unpacking to get each of the elements in the pair and how the condition if y == 1 filters only that element with a value of 1 in the second element of the pair. After that, you can do whatever you want with the elements found, in particular, I restore the original pair in this part on the left: (x, y)
source share