python iterate over multidimensional dictionary
d = {'dict1': {'foo': 1, 'bar': 2}, 'dict2': {'baz': 3, 'quux': 4}}
for i in d.keys():
print(i)
for j in d[i].keys():
print(j)
python iterate over multidimensional dictionary
d = {'dict1': {'foo': 1, 'bar': 2}, 'dict2': {'baz': 3, 'quux': 4}}
for i in d.keys():
print(i)
for j in d[i].keys():
print(j)
python iterate through dictionary
a_dict = {'apple':'red', 'grass':'green', 'sky':'blue'}
for key in a_dict:
print key # for the keys
print a_dict[key] # for the values
iterate through dictionary
#iterate the dict by keys
for key in a_dict:
print(key)
#iterate the dict by items - (key,value)
for item in a_dict.items():
print(item)
#iterate the dict by values
for value in a_dict.values():
print(value)
iterate through nested dictionary python
d = {'dict1': {'foo': 1, 'bar': 2}, 'dict2': {'baz': 3, 'quux': 4}}
for k1,v1 in d.iteritems(): # the basic way
temp = ""
temp+=k1
for k2,v2 in v1.iteritems():
temp = temp+" "+str(k2)+" "+str(v2)
print temp
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us