Skip to content

Commit e468f15

Browse files
committed
update sorted sample
1 parent 9c9ef92 commit e468f15

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

samples/functional/do_sorted.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,8 @@
88
print(sorted(L))
99
print(sorted(L, key=str.lower))
1010

11-
students = [
12-
('Adam', 90),
13-
('Tim', 60),
14-
('Lisa', 80),
15-
('Bart', 60)
16-
]
11+
students = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]
1712

18-
print(sorted(students, key=itemgetter(1)))
19-
20-
def student_to_key(t):
21-
return '%+02d%s' % (100-t[1], t[0])
22-
23-
print(sorted(students, key=student_to_key))
13+
print(sorted(students, key=itemgetter(0)))
14+
print(sorted(students, key=lambda t: t[1]))
15+
print(sorted(students, key=itemgetter(1), reverse=True))

0 commit comments

Comments
 (0)