Using Union and Dictionarie

Submitted 2 years, 8 months ago
Ticket #376
Views 273
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 2 years, 8 months ago

Wanna Post Ad?
Reach a large group of audience by posting an ad about your business here. For more details
Drop us a Message

Latest Blogs