Skip to content

Instantly share code, notes, and snippets.

@FerdinaKusumah
Last active December 5, 2019 01:51
Show Gist options
  • Save FerdinaKusumah/7e2a3e224d247f32145040a5de7e8057 to your computer and use it in GitHub Desktop.
Save FerdinaKusumah/7e2a3e224d247f32145040a5de7e8057 to your computer and use it in GitHub Desktop.
Merge Dictionary
"""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