How to add a couple of words "key-value" to the dictionary at the same time?

I have a dictionary dicthaving some elements like:

dict={'India':'Delhi','Canada':'Ottawa'}

Now I want to add a pair of vocabulary words to words in words dictlike:

dict= {'India':'Delhi','Canada':'Ottawa','USA':'Washington','Brazil':'Brasilia','Australia':'Canberra'}

Is there any way to do this? Because I do not want to add elements one by one.

+4
source share
1 answer

Use the method update().

d= {'India':'Delhi','Canada':'Ottawa'}
d.update({'USA':'Washington','Brazil':'Brasilia','Australia':'Canberra'})

PS: Naming your vocabulary as dicta terrible idea. It replaces the built-in dict.

+2
source

Source: https://habr.com/ru/post/1651893/


All Articles