# 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 = [("a", 1), ("b",2), ("c",3)]

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

print(test)

• Is this your entire program? If not, you need to show it. – Reinderien Jul 27 '20 at 14:43

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)