Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python, dictionaries In Exercises 60 and 61, use the file LargecitiesDict.dat th

ID: 3818463 • Letter: P

Question

Python, dictionaries

In Exercises 60 and 61, use the file LargecitiesDict.dat that stores a dictionary giving the large cities (population > 250,000) for each state. Each item of the dictionary has the form "name of state: list of large cities in that state''. The first three items in the dictionary are as follows: Alabama" [], Alaska": ["Anchorage"], "Arizona'': ["Phoenix "Tucson", "Mesa"] Write a program that requests the name of a state as input and then displays the large cities in that state. See Figs. 5.44 and 5.45. FIGURE 5.44 Possible outcome of Exercise 60. FIGURE 5.45 Possible outcome of Exercise 60.

Explanation / Answer

# pstebin link for code: https://pastebin.com/8n1t7741

import json

data = {}
with open('LargeCitiesDict.dat') as data_file:
data = json.load(data_file)

state = input("Enter the name of a state: ")
print("Large cities: " + " ".join(data[state]))

print(data)