Python nested dictionary comparison value, detailed explanation of value examples

零下一度
Release: 2017-06-23 10:49:15
Original
2997 people have browsed it
#取值
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')
Copy after login

Result:

##Compare size

def bijiaodict(dict1,dict2):for k,v in dict1.items():for k2,v2 in dict2.items():if k==k2 and v==v2:print('dict1=dict2')else:print('dict1!=dict2')
dict1={'2':'6'}
dict2={2:{1:{1:8}}}
bijiaodict(dict1,dict2)
Copy after login
Result:

The above is the detailed content of Python nested dictionary comparison value, detailed explanation of value examples. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template