135k views
2 votes
Given three dictionaries, associated with the variables, canadian_capitals, mexican_capitals, and us_capitals, that map provinces or states to their respective capitals, create a new dictionary that combines these three dictionaries, and associate it with a variable, nafta_capitals.

1 Answer

7 votes

Answer:

The Python code is explained below

Step-by-step explanation:

#Define the dictionary

#canadian_capitals.

canadian_capitals = {

'Alberta': 'Edmonton',

'British Columbia': 'Victoria',

'Ontario': 'Toronto',

'Manitoba': 'Winnipeg'

}

#Define the dictionary

#mexican_capitals.

mexican_capitals = {

'Puebla': 'Puebla',

'Sonora': 'Hermosillo',

'Tabasco': 'Villahermosa',

'Hidalgo': 'Pachuca'

}

#Define the dictionary

#us_capitals.

us_capitals = {

'Alabama': 'Montgomery',

'Alaska': 'Juneau',

'Georgia': 'Atlanta',

'California': 'Sacramento'

}

#De-hash the values of

#the dictionaries using

#the **operator and add them

#to the dictionary nafta_capitals.

nafta_capitals = {**canadian_capitals, **mexican_capitals, **us_capitals}

#Print the dictionary

#nafta_capitals.

print(nafta_capitals)

User Izabela Orlowska
by
3.9k points