Simplify : find if element is in tuples stored in list Is there a way to simplify this script using in keyword or anything like this:
searched_value = 3
data = [(&quot;a&quot;, 1), (&quot;b&quot;,2), (&quot;c&quot;,3)]

### can be simplified ?
test = None
for i in data:
    if i[1] == searched_value:
        test = i[0]
        break
###

print(test)
I don't think there is, except maybe unpacking the pairs:
test = None
for k, v in data:
    if v == searched_value:
        test = k
        break

You could use next, but I wouldn't call it simpler:
test = next((k for k, v in data if v == searched_value), None)