Skip to content

Commit c94f841

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

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

89/states.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ 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-
return sorted(data, key=lambda x: len(x))[-1]
54+
return max(data, key=len)
5555

5656

5757
def combine_state_names_and_abbreviations(us_state_abbrev=us_state_abbrev,
@@ -62,6 +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-
first10statesfromdict = list(sorted(us_state_abbrev.values()))[0:10]
66-
last10statesfromlist = sorted(states)[:-11:-1]
65+
first10statesfromdict = list(sorted(us_state_abbrev.values()))[:10]
66+
last10statesfromlist = sorted(states)[-10:]
6767
return sorted(last10statesfromlist+first10statesfromdict)

0 commit comments

Comments
 (0)