好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python嵌套字典比较值,取值的实例详解

#取值
import types
allGuests = {'Alice': {'apples': 5, 'pretzels': {'12':{'beijing':456}}},
             'Bob': {'ham sandwiches': 3, 'apple': 2},
             'Carol': {'cups': 3, 'apple pies': 1}}
def dictget(dict1,obj,default=None):
	for k,v in dict1.items():
		if k == obj:
			print(v)
		else:
			if type(v) is dict:
				re=dictget(v,obj)
				if re is not default:
					print(re)
dictget(allGuests,'beijing') 

查看更多关于python嵌套字典比较值,取值的实例详解的详细内容...

  阅读:37次