随笔分类 - python常用方法
摘要:data_list = ['中场', '后卫', '前锋', '守门员', '主教练', '助理教练'] sort_dic = {'守门员': 1, '前锋': 2, '中场': 3, '后卫': 4, '主教练': 0} sorted(data_list, key=lambda x:sort_di
阅读全文
摘要:根据参数类型,执行 装饰器指定类型的方法 from functools import singledispatch @singledispatch def func(arg): print(arg, ', 主函数') @func.register(int) def _(arg: int): prin
阅读全文
摘要:直接上代码 from enum import Enum, unique @unique class DAY(Enum): """ name和value都不可重复 """ MON: int = 1 TUE: int = 2 WED: int = 3 THU: int = 4 FRI: int = 5
阅读全文
摘要:1.查找列表中出现频率最高的值 # 方法一 a = [1, 1, 2, 3, 4, 4, 4, 5, 5, 6] max(a, key = a.count) # 方法二 from collections import Counter cnt = Counter(a) print(cnt.most_c
阅读全文

浙公网安备 33010602011771号