Using Union and Dictionarie

Submitted 3 years, 1 month ago
Ticket #376
Views 310
Language/Framework Python
Priority Low
Status Closed

How can merge two disctionaries in a single expression by taking union of dictionarie ?

Submitted on Mar 23, 21
add a comment

1 Answer


dict_one = {"one": "one", "two": 2, "three": 3}

dict_two = {"three": 4, "five": 5}

# dict_one will be the union of both dictionaries


# as of Python 3.9, you can use:
dict_one |= dict_two  # similar to update() method

# Notice: All keys are unique inside a dictionary, so in case that
# both dictionaries have one or more identical keys, Python will use
# the values from the second dictionary for those keys

Submitted 3 years, 1 month ago

Latest Blogs