有没有更便捷的方法啊

来源:5-7 Python替换list中的元素

xir0905

2020-10-09 13:41

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)


写回答 关注

2回答

  • 慕标7081267
    2021-03-27 12:13:48

    name = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']

    score = [89, 72, 88, 79, 99]

    scores = [89, 72, 88, 79, 99]

    score.sort(reverse = True)

    rank = []

    for i in range(len(score)):

        for j in range(len(score)):

            if score[i] == scores[j]:

                rank.append(name[j])

    print(rank)


  • Android精灵
    2020-10-10 11:02:15

    L = ['Alice','Bob','Candy','David','Ellena']

    L[0]='Ellena'

    L[1]='Alice'

    L[2]='Candy'

    L[3]='David'

    L[4]='Bob'

    print(L)


Python3 入门教程(新版)

python3入门教程,让你快速入门并能编写简单的Python程序

154156 学习 · 1075 问题

查看课程

相似问题