|
| 1 | +us_state_abbrev = {'Alabama': 'AL', 'Alaska': 'AK', 'Arizona': 'AZ', |
| 2 | + 'Arkansas': 'AR', 'California': 'CA', 'Colorado': 'CO', |
| 3 | + 'Connecticut': 'CT', 'Delaware': 'DE', 'Florida': 'FL', |
| 4 | + 'Georgia': 'GA', 'Hawaii': 'HI', 'Idaho': 'ID', |
| 5 | + 'Illinois': 'IL', 'Indiana': 'IN', 'Iowa': 'IA', |
| 6 | + 'Kansas': 'KS', 'Kentucky': 'KY', 'Louisiana': 'LA', |
| 7 | + 'Maine': 'ME', 'Maryland': 'MD', 'Massachusetts': 'MA', |
| 8 | + 'Michigan': 'MI', 'Minnesota': 'MN', 'Mississippi': 'MS', |
| 9 | + 'Missouri': 'MO', 'Montana': 'MT', 'Nebraska': 'NE', |
| 10 | + 'Nevada': 'NV', 'New Hampshire': 'NH', 'New Jersey': 'NJ', |
| 11 | + 'New Mexico': 'NM', 'New York': 'NY', |
| 12 | + 'North Carolina': 'NC', 'North Dakota': 'ND', |
| 13 | + 'Ohio': 'OH', 'Oklahoma': 'OK', 'Oregon': 'OR', |
| 14 | + 'Pennsylvania': 'PA', 'Rhode Island': 'RI', |
| 15 | + 'South Carolina': 'SC', 'South Dakota': 'SD', |
| 16 | + 'Tennessee': 'TN', 'Texas': 'TX', 'Utah': 'UT', |
| 17 | + 'Vermont': 'VT', 'Virginia': 'VA', 'Washington': 'WA', |
| 18 | + 'West Virginia': 'WV', 'Wisconsin': 'WI', 'Wyoming': 'WY'} |
| 19 | + |
| 20 | +states = ['Oklahoma', 'Kansas', 'North Carolina', 'Georgia', 'Oregon', |
| 21 | + 'Mississippi', 'Minnesota', 'Colorado', 'Alabama', |
| 22 | + 'Massachusetts', 'Arizona', 'Connecticut', 'Montana', |
| 23 | + 'West Virginia', 'Nebraska', 'New York', 'Nevada', 'Idaho', |
| 24 | + 'New Jersey', 'Missouri', 'South Carolina', 'Pennsylvania', |
| 25 | + 'Rhode Island', 'New Mexico', 'Alaska', 'New Hampshire', |
| 26 | + 'Tennessee', 'Washington', 'Indiana', 'Hawaii', 'Kentucky', |
| 27 | + 'Virginia', 'Ohio', 'Wisconsin', 'Maryland', 'Florida', |
| 28 | + 'Utah', 'Maine', 'California', 'Vermont', 'Arkansas', 'Wyoming', |
| 29 | + 'Louisiana', 'North Dakota', 'South Dakota', 'Texas', |
| 30 | + 'Illinois', 'Iowa', 'Michigan', 'Delaware'] |
| 31 | + |
| 32 | +NOT_FOUND = 'N/A' |
| 33 | + |
| 34 | + |
| 35 | +def get_every_nth_state(states=states, n=10): |
| 36 | + """Return a list with every nth item (default argument n=10, so every |
| 37 | + 10th item) of the states list above (remember: lists keep order)""" |
| 38 | + return [states[pos] for pos in range(n - 1, len(states), n)] |
| 39 | + |
| 40 | + |
| 41 | +def get_state_abbrev(state_name, us_state_abbrev=us_state_abbrev): |
| 42 | + """Look up a state abbreviation by querying the us_state_abbrev |
| 43 | + dict by full state name, for instance 'Alabama' returns 'AL', |
| 44 | + 'Illinois' returns 'IL'. |
| 45 | + If the state is not in the dict, return 'N/A' which we stored |
| 46 | + in the NOT_FOUND constant (takeaway: dicts are great for lookups)""" |
| 47 | + pass |
| 48 | + |
| 49 | + |
| 50 | +def get_longest_state(data): |
| 51 | + """Receives data, which can be the us_state_abbrev dict or the states |
| 52 | + list (see above). It returns the longest state measured by the length |
| 53 | + of the string""" |
| 54 | + pass |
| 55 | + |
| 56 | + |
| 57 | +def combine_state_names_and_abbreviations(us_state_abbrev=us_state_abbrev, |
| 58 | + states=states): |
| 59 | + """Get the first 10 state abbreviations ('AL', 'AK', 'AZ', ...) from |
| 60 | + the us_state_abbrev dict, and the last 10 states from the states |
| 61 | + list (see above) and combine them into a new list. The resulting list |
| 62 | + has both sorted, so: |
| 63 | + ['AK', 'AL', 'AZ', ..., 'South Dakota', 'Tennessee', 'Texas', ...] |
| 64 | + (see also test_combine_state_names_and_abbreviations)""" |
| 65 | + pass |
0 commit comments