问答详情
源自:5-7 Python替换list中的元素

是不是可以不用全部替换掉?

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

L[0]='Ellena'

L[1]='Alice'

L[4]='Bob'

print(L)


提问者:Chopper墨 2020-10-25 18:22

个回答

  • my藤上风铃
    2021-03-12 14:54:44

    # Enter a code

    # coding:utf-8

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

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


    templateNames = []

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


    scores.sort(reverse=True)

    print("降序排列后的成绩:" + str(scores))


    index_Score = 0

    index_TemplateScore = 0

    for score in scores:

        index_TemplateScore = 0


        for templateScore in templateScores:

            if score == templateScore:

                templateNames.append(names[index_TemplateScore])

            index_TemplateScore += 1


    print("排列后的名字:" + str(templateNames))


  • 慕运维0295976
    2020-11-26 14:04:41

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

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

    dictA=dict(zip(L,N))

    dictB=sorted(dictA, key=dictA.get, reverse = True)

    print(dictB)


  • 七月_Miss
    2020-10-26 15:45:24

    对的 不用全部替换