od 第86题 python 版本(精简版)
作者:互联网
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2022/6/5 22:59 # @Author : Jonathon # @File : 86.py # @Software: PyCharm # @ Motto : 客又至,当如何 def func(n, ids, score): ''' 题目要求: :param n: :param li: :return: ''' # d = dict(zip(ids, score)) # for i in d: # if d[i] < 3: # d.pop(i) d = {} se = set(ids) for i in se: d[i] = [] for k, v in zip(ids, score): d[k].append(v) for i in se: if d[i].__len__() < 3: d.pop(i) else: d[i] = sum(sorted(d[i][:3])) d_order = sorted(d.items(), key=lambda x: x[1], reverse=True) d_order = bubble(d_order) # for i in sorted(dict.items(), key=lambda x: x[1], reverse=True): # print(i) d_order = list(map(lambda x: x[0], d_order)) print(d_order) def bubble(li): # [(3, 188), (5, 188), (7, 139), (4, 139)] n = li.__len__() for i in range(n): for j in range(i + 1, n): if li[j - 1][1] == li[j][1]: if li[j - 1][0] < li[j][0]: li[j - 1], li[j] = li[j], li[j - 1] return li if __name__ == '__main__': ''' 13 3,3,7,4,4,4,4,7,7,3,5,5,5 53,80,68,24,39,76,66,16,100,55,53,80,55 ''' # func(13, [3, 3, 7, 4, 4, 4, 4, 7, 7, 3, 5, 5, 5], [53, 80, 68, 24, 39, 76, 66, 16, 100, 55, 53, 80, 55]) print(bubble([(3, 188), (5, 188), (7, 184), (4, 139)]))
标签:__,python,od,188,li,55,80,86,order 来源: https://www.cnblogs.com/icxk/p/16350253.html