Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

8,518 questions

11,802 answers

573 users

How to add two dictionaries to new dictionary in Python

5 Answers

0 votes
language1 = {'python': 13, 'php': 50, 'java': 6}
language2 = {'c++': 2, 'c#': 87, 'javascript': 52}

new_dic = dict(language1)
new_dic.update(language2)

print(new_dic)


'''
run:

{'python': 13, 'php': 50, 'java': 6, 'c++': 2, 'javascript': 52, 'c#': 87}
 
'''

 




answered Aug 29 by avibootz
0 votes
language1 = {'python': 13, 'php': 50, 'java': 6}
language2 = {'c++': 2, 'c#': 87, 'javascript': 52}

new_dic = language1.copy()
new_dic.update(language2)

print(new_dic)


'''
run:

{'php': 50, 'python': 13, 'javascript': 52, 'c++': 2, 'java': 6, 'c#': 87}
 
'''

 




answered Aug 29 by avibootz
0 votes
language1 = {'python': 13, 'php': 50, 'java': 6}
language2 = {'c++': 2, 'c#': 87, 'javascript': 52}
 
new_dic = {**language1, **language2}

print(new_dic)
 
 
'''
run:
 
{'php': 50, 'c++': 2, 'java': 6, 'python': 13, 'c#': 87, 'javascript': 52}
  
'''

 




answered Aug 29 by avibootz
0 votes
from itertools import chain

language1 = {'python': 13, 'php': 50, 'java': 6}
language2 = {'c++': 2, 'c#': 87, 'javascript': 52}

new_dic = dict(chain(language1.items(), language2.items()))

print(new_dic)


'''
run:

{'javascript': 52, 'php': 50, 'c++': 2, 'python': 13, 'java': 6, 'c#': 87}
  
'''

 




answered Aug 29 by avibootz
0 votes
language1 = {'python': 13, 'php': 50, 'java': 6}
language2 = {'c++': 2, 'c#': 87, 'javascript': 52}

new_dic = dict(list(language1.items()) + list(language2.items()))

print(new_dic)


'''
run:

{'php': 50, 'java': 6, 'python': 13, 'c++': 2, 'javascript': 52, 'c#': 87}
  
'''

 




answered Aug 29 by avibootz
...