大家好,我是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.