Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python merge two dictionaries in a single expression

z = {**x, **y}  #python 3.5 and above

z = x | y    #python 3.9+ ONLY

def merge_two_dicts(x, y): # python 3.4 or lower
      z = x.copy()   # start with x's keys and values
      z.update(y)    # modifies z with y's keys and values & returns None
      return z
Comment

Merge two dictionaries in a single expression

currentEmployee = {1: 'Scott', 2: "Eric", 3:"Kelly"}
formerEmployee  = {2: 'Eric', 4: "Emma"}
Comment

Merge two dictionaries in a single expression

currentEmployee = {1: 'Scott', 2: "Eric", 3:"Kelly"}
formerEmployee  = {2: 'Eric', 4: "Emma"}

allEmployee = {**currentEmployee, **formerEmployee}
print(allEmployee)
Comment

PREVIOUS NEXT
Code Example
Python :: merge two Python dictionaries in a single expression 
Python :: reverse an array python 
Python :: get rid of unnamed column pandas 
Python :: sort a series pandas 
Python :: accept user input in python 
Python :: random question generator python 
Python :: how to create a tuple from csv python 
Python :: python get file path from in os.walk 
Python :: import local module python 
Python :: python wait for x seconds 
Python :: fizzbuzz python solution 
Python :: python remove string from string 
Python :: Read all the lines as a list in a file using the readlines() function 
Python :: python exit for loop 
Python :: pandas sort by columns 
Python :: python remove consecutive spaces 
Python :: enum python 
Python :: opencv python image capture 
Python :: elif in django template 
Python :: decision tree regressor 
Python :: pandas count unique values in column 
Python :: spacy config 
Python :: how to start a new django project 
Python :: python recurrent timer 
Python :: sort series in ascending order 
Python :: python insertion sort 
Python :: python 2 deprecated 
Python :: try except keyerror 
Python :: list files python 
Python :: discord.py say something 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =