有没有更便捷的方法啊
names=['Alice', 'Bob', 'Candy', 'David', 'Ellena']
grade=[89, 72, 88, 79, 99]
for i in range(4):
for j in range(i+1,5):
if grade[j]>grade[i]:
names[i],names[j]=names[j],names[i]
grade[i],grade[j]=grade[j],grade[i]
print(names)
names=['Alice', 'Bob', 'Candy', 'David', 'Ellena']
grade=[89, 72, 88, 79, 99]
for i in range(4):
for j in range(i+1,5):
if grade[j]>grade[i]:
names[i],names[j]=names[j],names[i]
grade[i],grade[j]=grade[j],grade[i]
print(names)
2020-10-09
举报