python - get key by value in dictionary - Stack Overflow

python - get key by value in dictionary - Stack Overflow

瀏覽:1358
日期:2025-04-24
If you want both the name and the age, you should be using .items() which gives you key (key, value) tuples: for name, age in mydict.items(): if age == search_age: print name You can unpack the tuple into two separate variables right in the for loop, then...看更多