数组排序

  • 对以下数组进行排序:要求排序优先级 score > name > age。 如果分数相同,按照名字排序,如果名字依然相同,按照年龄排序

    People = [ (‘David’, ‘17’, ‘122’), (‘Mike’, ‘18’, ‘120’), (‘Juno’, ‘18’,’120’), (‘David’, ‘19’, ‘122’), (‘Juno’, ‘21’, ‘100’)]

    冒泡算法解答

    people = [('David',17,122),('Mike',18,120,),('Juno',18,120),('David',19,122),('Juno',21,100)]
    j = 0
    while j < len(people):
    for i in range(len(people) - j - 1):
        if people[i][2] < people[i + 1][2]:
            people[i], people[i + 1] = people[i + 1], people[i]
        if people[i][2] == people[i + 1][2]:
            if people[i][0] < people[i + 1][0]:
                people[i], people[i + 1] = people[i + 1], people[i]
            if people[i][0] == people[i + 1][0]:
                if people[i][1] < people[i + 1][1]:
                    people[i], people[i + 1] = people[i + 1], people[i]
    j += 1
    print(people)
©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值