DEV Community

Discussion on: Instructive Python code examples for Beginners

Collapse
 
ranggakd profile image
Retiago Drago

Since I love dict, number #4 could be one liner like this 🚀

def merge(dic1,dic2):
    return {**dic1,**dic2}
dic1={1:"Hello", 2:"Dev"}
dic2={2:"Python", 4:"Programming"}
# In these examples, Python merges dictionary keys
# in the order listed in the expression, overwriting 
# duplicates from left to right.
merge(dic1,dic2) # {1: 'Hello', 2: 'Python', 4: 'Programming'}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
vadimkolobanov profile image
Vadim Kolobanov

A very beautiful option) Thanks. I'll replace this if you don't mind)

Collapse
 
ranggakd profile image
Retiago Drago

I'll be honoured ✌