Last active
December 5, 2019 01:51
-
-
Save FerdinaKusumah/7e2a3e224d247f32145040a5de7e8057 to your computer and use it in GitHub Desktop.
Merge Dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Merge dict""" | |
a = {"apple": 10} | |
b = {"banana": 3} | |
example1 = {**a, **b} | |
print("Merge dict 1 to {}".format(example1)) | |
# Merge dict 1 to {'apple': 10, 'banana': 3} | |
example2 = dict(a.items() | b.items()) | |
print("Merge dict 2 to {}".format(example2)) | |
# Merge dict 2 to {'banana': 3, 'apple': 10} | |
a.update(b) | |
example3 = a | |
print("Merge dict a to {}".format(example3)) | |
# Merge dict a to {'apple': 10, 'banana': 3} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment