python 2.7 - How can I merge two or more dictionaries in a list? -


is there nice pythonic way of merging dictionaries within list?

what have:

[     { 'name': "jack" },     { 'age': "28" } ] 

what like:

[     { 'name': "jack", 'age': "28" } ] 

here's method uses dict.update(). in opinion it's readable solution:

data = [{'name': 'jack'}, {'age': '28'}]  new_dict = {} d in data:     new_dict.update(d)  new_data = [new_dict]  print new_data 

output

[{'age': '28', 'name': 'jack'}]


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -