Finding the key to a value
Published: Wednesday, Dec 26, 2007 Last modified: Thursday, Nov 14, 2024
Use a list comprehension:
hit = [k for k,v in dict.items() if v==lookingfor]
Use a list comprehension:
hit = [k for k,v in dict.items() if v==lookingfor]