Search code snippets, questions, articles...

Merge two or multiple dictionaries in Python

There are several ways to merge or concatenate two or more dictionaries in python. In this post, We will explain the methods and techniques to join two or more dictionaries in Python.
user_info = {
  "name": "John",
  "email": "test@test.com"
}

address_info = {
  "city": "New York",
  "country": "USA"
}

#Merge using .update() method
user_info.update(address_info)
print(user_info);

#Merge using ** operator
merged = {**user_info, **address_info}
print(merged)
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

Output

{'name': 'John', 'email': 'test@test.com', 'city': 'New York', 'country': 'USA'}
{'name': 'John', 'email': 'test@test.com', 'city': 'New York', 'country': 'USA'}

Search Index Data (The code snippet can also be found with below search text)

concatenate two dictionaries in python
Was this helpful?
0 Comments