filmov
tv
Merge two Dictionaries in Python (Update) - Python Tutorial for Beginners

Показать описание
🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!
🖥️ Merge two Dictionaries in Python (Update)
You may sometimes want or need to merge two dictionaries, so that you can have ALL of your data located in the same variable. Or even update its values, with new content. Thus, use the built-in method update(), to merge the keys and values from one dictionary, into another dictionary.
Note: This method update() blindly overwrites values of the same key.
If there was already an existing key inside of the first dictionary, its value will be updated with the new one. And news keys will be created, if there were not already existing.
As you can see in this example, merging the two dictionaries in Python will result in combining ALL of the items from both dictionaries, and updating the ones that were existed before.
my_dict1 = {
'age': 25,
'job': 'Youtuber',
'name': 'Digital Academy'
}
my_dict2 = {
'age': 27,
'city': 'Paris',
}
Let's play this video, stick around and watch until the end of this video! 👍🏻
- Digital Academy™ 🎓
***
☞ WATCH NEXT:
#Python #Tutorial #Beginners #Shorts
***
♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.
***
♡ FOLLOW US ♡
♡ SUPPORT US ♡
***
🖥️ Merge two Dictionaries in Python (Update)
You may sometimes want or need to merge two dictionaries, so that you can have ALL of your data located in the same variable. Or even update its values, with new content. Thus, use the built-in method update(), to merge the keys and values from one dictionary, into another dictionary.
Note: This method update() blindly overwrites values of the same key.
If there was already an existing key inside of the first dictionary, its value will be updated with the new one. And news keys will be created, if there were not already existing.
As you can see in this example, merging the two dictionaries in Python will result in combining ALL of the items from both dictionaries, and updating the ones that were existed before.
my_dict1 = {
'age': 25,
'job': 'Youtuber',
'name': 'Digital Academy'
}
my_dict2 = {
'age': 27,
'city': 'Paris',
}
Let's play this video, stick around and watch until the end of this video! 👍🏻
- Digital Academy™ 🎓
***
☞ WATCH NEXT:
#Python #Tutorial #Beginners #Shorts
***
♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.
***
♡ FOLLOW US ♡
♡ SUPPORT US ♡
***
Комментарии