python - Print dictionary of list values -


i have list of dictionary values, given below:

{'id 2': [{'game': 586, 'start': 1436882375, 'process': 13140}, {'game': 585, 'start': 1436882375, 'process': 13116}], 'id 1': [{'game': 582, 'start': 1436882375, 'process': 13094}, {'game': 583, 'start': 1436882375, 'process': 12934}, {'game': 584, 'start': 1436882375, 'process': 12805}]} 

it barely readable. want format way:

'id 2' : {'game': 586, 'start': 1436882375, 'process': 13140}, 'id 2' : {'game': 585, 'start': 1436882375, 'process': 13116}, 'id 1' : {'game': 582, 'start': 1436882375, 'process': 13094}, 'id 1' : {'game': 582, 'start': 1436882375, 'process': 13094}, 

my code printing given below:

 key in queue_dict.items():         values in key.values():             print(key+" : "+values) 

the error is:

attributeerror: 'tuple' object has no attribute 'values' 

i cannot understand how access each dictionary in list value of each key. searched lot, couldn't find answer. can help?

dict.items returns tuple of key value pairs.

return new view of dictionary’s items ((key, value) pairs)

you have instead.

for key,values in queue_dict.items():      v in values:           print(key," : ",v) 

also can not concatenate str object , dict object using +. typeerror. have cast str. instead can use format in print("{} : {}".format(key,v))


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -