Chrome Extension

Merge two or multiple dictionaries in Python

There are several ways to merge or concatenate two or more dictionaries in python. The code for them is as below.
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

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

concatenate two dictionaries in python
Was this helpful?
0 Comments