Skip to content

Commit dc60b35

Browse files
bites 89 - Playing with list and dict(Completed)
1 parent 4445032 commit dc60b35

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

89/states.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ def get_state_abbrev(state_name, us_state_abbrev=us_state_abbrev):
4444
'Illinois' returns 'IL'.
4545
If the state is not in the dict, return 'N/A' which we stored
4646
in the NOT_FOUND constant (takeaway: dicts are great for lookups)"""
47-
pass
47+
return us_state_abbrev.get(state_name, "N/A")
4848

4949

5050
def get_longest_state(data):
5151
"""Receives data, which can be the us_state_abbrev dict or the states
5252
list (see above). It returns the longest state measured by the length
5353
of the string"""
54-
pass
54+
return sorted(data, key=lambda x: len(x))[-1]
5555

5656

5757
def combine_state_names_and_abbreviations(us_state_abbrev=us_state_abbrev,
@@ -62,4 +62,6 @@ def combine_state_names_and_abbreviations(us_state_abbrev=us_state_abbrev,
6262
has both sorted, so:
6363
['AK', 'AL', 'AZ', ..., 'South Dakota', 'Tennessee', 'Texas', ...]
6464
(see also test_combine_state_names_and_abbreviations)"""
65-
pass
65+
first10statesfromdict = list(sorted(us_state_abbrev.values()))[0:10]
66+
last10statesfromlist = sorted(states)[:-11:-1]
67+
return sorted(last10statesfromlist+first10statesfromdict)

0 commit comments

Comments
 (0)