Skip to content

Commit 0138df3

Browse files
committed
adding multiple itemgetter
1 parent 7289faf commit 0138df3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sort-python-dictionary/using_itemgetter.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,16 @@
2424
people = {3: "Jim", 2: "Jack", 4: "Jane", 1: "Jill"}
2525

2626
sorted(people.items(), key=itemgetter(1)) # Sort by value
27+
28+
29+
scores = {
30+
"Jack": 14,
31+
"Jill": 14,
32+
"John": 15,
33+
"Jane": 15,
34+
"Jim": 14,
35+
"Jess": 14,
36+
}
37+
38+
# Sorts by value, but keeps names in alphabetical order
39+
print(sorted(scores.items(), key=itemgetter(1, 0)))

0 commit comments

Comments
 (0)