
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program to Concatenate Two Dictionaries Into One
When it is required to concatenate two dictionaries into a single entity, the ‘update’ method can be used.
A dictionary is a ‘key-value’ pair.
Below is a demonstration for the same −
Example
my_dict_1 = {'J':12,'W':22} my_dict_2 = {'M':67} print("The first dictionary is :") print(my_dict_1) print("The second dictionary is :") print(my_dict_2) my_dict_1.update(my_dict_2) print("The concatenated dictionary is :") print(my_dict_1)
Output
The first dictionary is : {'J': 12, 'W': 22} The second dictionary is : {'M': 67} The concatenated dictionary is : {'J': 12, 'W': 22, 'M': 67}
Explanation
Two dictionaries are defined, and are displayed on the console.
- The ‘update’ method is called on the first dictionary by passing second dictionary as parameter.
- This would help concatenate the dictionary.
- This is displayed on the console.
- Related Articles
- Python program to merge two Dictionaries
- Python Program to compare elements in two dictionaries
- C# program to merge two Dictionaries
- How to concatenate two files into a new file using Python?
- Python program to merge to dictionaries.
- Java Program to Concatenate Two Arrays
- C++ Program to Concatenate Two Strings
- Python - Intersect two dictionaries through keys
- C# program to merge two sorted arrays into one
- How to concatenate two strings in Python?
- How can we merge two Python dictionaries?
- Python - Difference in keys of two dictionaries
- Python program to concatenate Strings around K
- How to merge two Python dictionaries in a single expression?
- How do we compare two dictionaries in Python?

Advertisements