Home > Net >  how to match a word with a list of tubles
how to match a word with a list of tubles

Time:02-12

i am trying to find a word in a list of tuples. I tried the following code

 keywords_adera = [('athletes', 0.4235), ('scrimmages', 0.3895),('athlete', 0.379),('sport', 0.3714),('soccer', 0.3699)]
b_adera='athletes'
if b_adera in keywords_adera2:
    print('macrious4')

the code does not give any output. Any suggestions are appreciated.

CodePudding user response:

You have to iterate over a list keywords_adera Then you check if your searched word is in current tuple

for t in lst:
    if word in t:
        print('found')

CodePudding user response:

The tuple is in list you need to match entier tuple with Value for if statement to be true

 keywords_adera = [('athletes', 0.4235), ('scrimmages', 0.3895), 
 ('athlete', 0.379),('sport', 0.3714),('soccer', 0.3699)]
  b_adera=('athletes',0.4235)
  if b_adera in keywords_adera:
      print('macrious4')

Else you would need to iterate over list or specify which index in list

  • Related