-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,278
  • 2
  • 18
  • 21
satheesh
  • 83
  • 2
  • 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,534
  • 1
  • 10
  • 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,022
  • 4
  • 23
  • 37