How to get a key from a value in Python

preview_player
Показать описание


Code from video:
*****************
employees = {1: 'michael', 2: 'eric', 3: 'michael'}

Connect with us!
*****************
Рекомендации по теме
Комментарии
Автор

what if i have multiple keys in the the dictionary and i am storing list for each key like dic = { "animals" : ["dog", "cat", "horse"], "games": ["lol", "csgo", "pubg"] } <- how should i get key by any of the list value

kajalchauhan
Автор

PKName = input("What is the name of the Pokémon? | ")
[number for number, name in Pokédex.items() if name == PKName]


is there anything wrong with this?
it should be returning 4


the dictionary is
{"1":"Bulbasaur",
"2":"Ivysaur",
"3":"Venusaur",
"4":"Charmander",
"5":"Charmeleon",
"6":"Charizard",
"7":"Squirtle",
"8":"Wartortle",
"9":"Blastoise"
}

weebtendo
Автор

too bad you guys cancelled your on-demand python courses.. it was the single best resource on the internet, and it was free for academia which was especially convenient..
i hope you change your mind at some point haha!

ddarhe