Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,902 questions

51,833 answers

573 users

How to merge two dictionaries in Python

3 Answers

0 votes
workers1 = {'name': "dan", 'age': 46}
workers2 = {'name': "r2d2", 'price': 3490}

workers1.update(workers2)
  
print(workers1) 
print(workers2)



'''
run:

{'name': 'r2d2', 'age': 46, 'price': 3490}
{'name': 'r2d2', 'price': 3490}

'''

 



answered Feb 19, 2019 by avibootz
0 votes
def merge(dict1, dict2): 
    return {**dict1, **dict2} 

workers1 = {'name': "dan", 'age': 46}
workers2 = {'name': "r2d2", 'price': 3490}

mrg = merge(workers1, workers2)
  
print(workers1) 
print(workers2)
print(mrg)



'''
run:

{'name': 'dan', 'age': 46}
{'name': 'r2d2', 'price': 3490}
{'name': 'r2d2', 'age': 46, 'price': 3490}

'''

 



answered Feb 19, 2019 by avibootz
0 votes
dic1 = {'a': 4, 'b': 3, 'c': 7, 'd': 9}
dic2 = {'e': 100, 'f': 30, 'g': 50}
 
dic1.update(dic2)
 
print(dic1)
print(dic2)
 
   
   
   
   
'''
run:
   
{'a': 4, 'b': 3, 'c': 7, 'd': 9, 'e': 100, 'f': 30, 'g': 50}
{'e': 100, 'f': 30, 'g': 50}
 
'''

 



answered Apr 18, 2024 by avibootz

Related questions

4 answers 190 views
1 answer 128 views
1 answer 139 views
139 views asked Dec 15, 2022 by avibootz
2 answers 152 views
152 views asked Dec 15, 2022 by avibootz
...