-1
first_obj= [{"name":"sat","age":20}]
second_obj = [{"country":'India'}]

How to add array of dictionary in python?

third_obj = [{"name":'sat',"age":20,"country":'India'}]
Fynn Becker
  • 1,037
  • 2
  • 16
  • 19
satheesh
  • 73
  • 1
  • 2
  • 4

2 Answers2

1
first_obj= [{"name":"sat","age":20}]
second_obj = [{"country":'India'}]

third_obj = [{**first_obj[0], **second_obj[0]}]
print(third_obj)

Output

[{'name': 'sat', 'country': 'India', 'age': 20}]
Filip Młynarski
  • 3,414
  • 1
  • 9
  • 22
0

Assuming both objects will always have the same length, you can iterate both lists and merge the dictionaries:

third_obj = []
for a, b in zip(first_obj, second_obj):
   combined_dict = dict(a.items() + b.items()) # merge dictionaries
   third_obj.append(combined_dict)
nico
  • 2,000
  • 4
  • 22
  • 37