I have a list like
list_a = [(1, 2), (2, 3), (4, 5)]
and now using this list i wanted to find a element which has last value 3 any short method to achieve this? it should return (2,3)
For example:
In [1]: list_a = [(1, 2), (2, 3), (4, 5)]
In [2]: next(x for x in list_a if x[1] == 3)
Out[2]: (2, 3)
Note that it returns a single element, not a list of them (seems to be what you are asking). If there are multiple tuples, the first one is returned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With