america = [ 'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming', ] ########################################################################## # print all states that start with 'Co' print print "The following states start with the letter 'Co':" for state in america: if state.startswith('Co'): print state ########################################################################## # create a list of states that start with 'Co' print print "List of States starting with Co:", results = [] for state in america: if state.startswith('Co'): results.append(state) print results ########################################################################## print print 'A state with the longest name is', bestScore = 0 # biggest length we've seen so far... winner = None # the state with that length for state in america: realLength = len(state.replace(' ','')) # don't count spaces if realLength >= bestScore: bestScore = realLength winner = state print winner print '(with length of ' + str(bestScore) + ')' ########################################################################## print print 'The states with the longest name are', bestScore = 0 # biggest length we've seen so far... results = [] for state in america: realLength = len(state.replace(' ','')) # don't count spaces if realLength >= bestScore: if realLength == bestScore: # ties for the longest so far results.append(state) else: # surpasses the longest so far bestScore = realLength # record new best score results = [ state ] # and restart with new list print results ########################################################################## print print 'A state with the shortest name is', bestScore = len(america[0]) # an upper bound on the smallest length winner = america[0] # the state with that length for state in america: realLength = len(state.replace(' ','')) # don't count spaces if realLength < bestScore: bestScore = realLength winner = state print winner ########################################################################## print print 'States that have more than one word names: ', ########################################################################## print print 'The letter of the alphabet starting the most states is', ########################################################################## print print 'Our attempt at making two-letter abbreviations:' ##########################################################################