I have a dictionary with each keys having multiple values in a list. The tasks are:
- To detect whether a given word is in the dictionary values
- If it is true, then return the respective key from the dictionary
Task 1 is achieved by using an if condition:
if (word in dictionary[topics] for topics in dictionary.keys())
I want to get the topics when the if condition evaluates to be True. Something like
if (word in dictionary[topics] for topics in dictionary.keys()):
print topics
Aucun commentaire:
Enregistrer un commentaire