You are given a dictionary of the US states and their capitals. The keys in the dictionary are states and the values are capital names.
Write a code to return a list of all capitals that contain the name of a state in their name as a substring.
HINT: For example, Indiana as a capital name and Indianapolis as a state name is one of the key/value pairs that your code would find. Your code should add Indianapolis to the list. After you found all capitals and added them to the list, print out the list
Run this cell to create a dictionary of states' capitals
capitals={'Alabama': 'Montgomery','Alaska': 'Juneau','Arizona':'Phoenix','Arkansas':'Little Rock','California': 'Sacramento','Colorado':'Denver','Connecticut':'Hartford','Delaware':'Dover','Florida': 'Tallahassee','Georgia': 'Atlanta','Hawaii': 'Honolulu','Idaho': 'Boise','Illinios': 'Springfield','Indiana': 'Indianapolis','Iowa': 'Des Monies','Kansas': 'Topeka','Kentucky': 'Frankfort','Louisiana': 'Baton Rouge','Maine': 'Augusta','Maryland': 'Annapolis','Massachusetts': 'Boston','Michigan': 'Lansing','Minnesota': 'St. Paul','Mississippi': 'Jackson','Missouri': 'Jefferson City','Montana': 'Helena','Nebraska': 'Lincoln','Neveda': 'Carson City','New Hampshire': 'Concord','New Jersey': 'Trenton','New Mexico': 'Santa Fe','New York': 'Albany','North Carolina': 'Raleigh','North Dakota': 'Bismarck','Ohio': 'Columbus','Oklahoma': 'Oklahoma City','Oregon': 'Salem','Pennsylvania': 'Harrisburg','Rhoda Island': 'Providence','South Carolina': 'Columbia','South Dakota': 'Pierre','Tennessee': 'Nashville','Texas': 'Austin','Utah': 'Salt Lake City','Vermont': 'Montpelier','Virginia': 'Richmond','Washington': 'Olympia','West Virginia': 'Charleston','Wisconsin': 'Madison','Wyoming': 'Cheyenne'
}
Code:
result = []
for x in capitals.keys():if(x in capitals[x]):result.append(capitals[x])
print(result)