Created
March 12, 2021 15:54
-
-
Save pavelanni/800a1de2d7c85881b751868208f1d5e3 to your computer and use it in GitHub Desktop.
Python: Add items to a dict from a second dict without changing the existing ones
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
d1 = {'a': 1, 'b': 2, 'c': 3} | |
d2 = {'d': 4, 'e': 5, 'a': 6} | |
d1.update({k:v for (k,v) in d2.items() if k not in d1}) | |
d1 | |
# Out: {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment