Skip to content

Commit f70987c

Browse files
committed
Fix sorting of shells & users
* The return value didn't sort the shells, sorted(shells.list,key=len) does nothing, as the length of each tuple is 2: the key & the value, while you obviously wanted the length of the user list * The exercise also requested listing the usernames '(sorted alphabetically)'
1 parent 4f956bd commit f70987c

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

ch03-lists-tuples/e12b3_shells_and_users.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ def shells_and_users_by_popularity(filename):
1414

1515
shells[shell].append(username)
1616

17-
return sorted(shells.items(), key=len)
17+
# sort usernames for each shell:
18+
for shell in shells:
19+
shells[shell] = sorted(shells[shell])
20+
21+
return {s: shells[s] for s in sorted(shells.keys(), key=lambda s: len(shells[s]), reverse=True)}

0 commit comments

Comments
 (0)