Skip to content

Instantly share code, notes, and snippets.

@FerdinaKusumah
Created July 28, 2020 13:48
Show Gist options
  • Save FerdinaKusumah/93dec317a9427e413df3b820a5881b25 to your computer and use it in GitHub Desktop.
Save FerdinaKusumah/93dec317a9427e413df3b820a5881b25 to your computer and use it in GitHub Desktop.
[Python] merge dictionary
"""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