Created
August 14, 2022 12:49
-
-
Save sebastianschramm/126c30b1b8e1aab700540476f9dc0e72 to your computer and use it in GitHub Desktop.
Two ways to combine two dictionaries with unique keys
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
first_dict = {"a": 1, "b": "foo"} | |
second_dict = {"c": 1, "d": 5.5, "e": "bar"} | |
combined_dict_1 = first_dict | second_dict | |
combined_dict_2 = {**first_dict, **second_dict} | |
assert combined_dict_1 == combined_dict_2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment