Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if word is inside of list of tuples

I'm wondering how I can efficiently check whether a value is inside a given list of tuples. Say I have a list of:

("the", 1)
("check", 1)
("brown, 2)
("gary", 5)

how can I check whether a given word is inside the list, ignoring the second value of the tuples? If it was just a word I could use

if "the" in wordlist:
   #...

but this will not work, is there something along the line this i can do?

if ("the", _) in wordlist:
   #...
like image 606
Syntactic Fructose Avatar asked Nov 29 '22 23:11

Syntactic Fructose


1 Answers

May be use a hash

>>> word in dict(list_of_tuples)
like image 155
Meitham Avatar answered Dec 14 '22 11:12

Meitham