May-31-2019, 06:00 PM
Question: Find a substring
You are given a dictionary of the US states and their capitals (my actual list is larger than provided below). 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, Indianapolis as a capital name and Indiana 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
You are given a dictionary of the US states and their capitals (my actual list is larger than provided below). 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, Indianapolis as a capital name and Indiana 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={ 'Illinios': 'Springfield', 'Indiana': 'Indianapolis', 'Oklahoma': 'Oklahoma City', 'Oregon': 'Salem', }I believe I have to use substring or contains. I am new to Python. I appreciate it, thank you.
capitals={capital:state} list_of_all_capitals=[] for capital in state list_of_all_capitals.append=[capital] print(list_of_all_capitals)