这个只能手动排序吗 那如果人数很多要怎么操作
问题描述:
有主动排序的方法吗
问题描述:
有主动排序的方法吗
2021-07-31
自己写代码:
结果:
[99, 89, 88, 79, 72] ['Ellena', 'Alice', 'Candy', 'David', 'Bob']
代码:
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
scores = [89, 72, 88, 79, 99]
for i in range(len(scores)):
s = scores[i]
flag = i
for j in range(i,len(scores)):
if(scores[flag] < scores[j]):
flag = j
temp = ''
x = 0
temp = names[i]
names[i] = names[flag]
names[flag] = temp
x = scores[i]
scores[i] = scores[flag]
scores[flag] = x
print(scores)
print(names)
举报