我有一个包含许多词典的列表,我需要为每个词典获取键和值:
[{'keys1.1' = 'value1.1','key1.2'='values1.2'},{'keys2.1'='value2.1'},{'key3.1'='value3.1'}]
我如何获得这些键和值?
答案 0 :(得分:0)
您需要遍历dict
中的for-loop
:
list_of_dicts = [{'keys1.1' : 'value1.1',
'key1.2':'values1.2'},
{'keys2.1':'value2.1'},
{'key3.1':'value3.1'}]
for item in list_of_dicts:
for key, value in item.iteritems()
print key, value
print "The key is {0} with a value of {1}".format(key, value)
#or
for item in list_of_dicts:
for key in item.keys():
print item[key]
print "The key is {0} with a value of {1}".format(key, item[key])