forked from xiaobh2010/-python-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sorted.py
23 lines (20 loc) · 1.07 KB
/
sorted.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def score_high2low(all_info):
res=sorted(all_info,key=lambda all_info:all_info['score'],reverse=True)
print('按成绩从高至低打印学生信息:')
for n in res:
print('|%s|%s|%s|' % (n['name'].center(20),str(n['age']).center(6),str(n['score']).center(6)))
def score_low2high(all_info):
res=sorted(all_info,key=lambda all_info:all_info['score'])
print('按成绩从低至高打印学生信息:')
for n in res:
print('|%s|%s|%s|' % (n['name'].center(20),str(n['age']).center(6),str(n['score']).center(6)))
def age_high2low(all_info):
res=sorted(all_info,key=lambda all_info:all_info['age'],reverse=True)
print('按年龄从高至低打印学生信息:')
for n in res:
print('|%s|%s|%s|' % (n['name'].center(20),str(n['age']).center(6),str(n['score']).center(6)))
def age_low2high(all_info):
res=sorted(all_info,key=lambda all_info:all_info['age'])
print('按年龄从低至高打印学生信息:')
for n in res:
print('|%s|%s|%s|' % (n['name'].center(20),str(n['age']).center(6),str(n['score']).center(6)))