大家好,我是Python 超級新手,最近自學遇到dict問題,卡關好多天了,麻煩大家教教
我了。
A = { 'fruits': { 'apple': 10, 'bananas': 30, 'orange': 22 }, 'meat': { 'beef'
: 50, 'pork': 45, 'chicken':30 } }
當我輸入30時,如何得到對應的key: bananas & chicken 的答案?反過來,如果是知道A
pple 怎麼得到它的value呢?
我只會從最外面一層一層進去查
例:A['meat']['beef'] = 50
一直想不出可以用什麼方法找出內層字典的 key & value 啊......
感激不盡了!
you need to know the outer key in order to getthe inner dict. And from your first case, you are trying to get the keys from given value which is not what a dict can do. You need to writea class which extends dict and implement this special method.