Let's say I have a dictionary of all states abbreviations as a key, and the long names as the value:
statesDict = {'AK': 'Alaska', 'AL': 'Alabama', 'AR': 'Arkansas',...}
I also have a list of pre-selected state abbreviations:
statesAbbrv = ['AL', 'CA', 'CO', 'DE']
Based on the items in the cleanStates list, I want to chose only the values (the long names) for the state abbreviations keys in the stateNames dictionary and place them in a new list; stateNames = [] So, the results of the comparison will look like this:
stateNames = ['Alabama', 'California', 'Colorado', 'Deleware']
I was thinking the following, but it's not working. What am I doing wrong here?
stateNames = []
for i in statesAbbrv:
for k, v in statesDict:
if stateDict[k] == stateAbbrv[i]:
stateNames.append(stateDict(k))
print stateNames