Created
July 28, 2020 13:48
-
-
Save FerdinaKusumah/93dec317a9427e413df3b820a5881b25 to your computer and use it in GitHub Desktop.
[Python] merge dictionary
This file contains hidden or 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 dictionary""" | |
words = {"a": 1, "b": 2, "c": 3} | |
number = {"1": 1, "2": 2, "3": 3} | |
"""example 1""" | |
ex_1 = {**words, **number} | |
# merge dictionary a, b = {'a': 1, 'b': 2, 'c': 3, '1': 1, '2': 2, '3': 3} | |
"""example 2""" | |
ex_2 = dict(words.items() | number.items()) | |
# merge dictionary a, b = {'3': 3, 'c': 3, '2': 2, 'b': 2, '1': 1, 'a': 1} | |
"""example 3""" | |
words.update(number) | |
ex_3 = words | |
# merge dictionary a, b = {'a': 1, 'b': 2, 'c': 3, '1': 1, '2': 2, '3': 3} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment