编写不易如果觉得不错,麻烦关注一下~
1、dict 类型寻找top k 按照value值大小
参考连接:
【1】https://www.cnblogs.com/lutt/p/12723267.html
【2】https://www.cnblogs.com/whaben/p/6495702.html
d = {'lilee':25, 'wangyan':21, 'liqun':32, 'age':19}
print(sorted(d.items(), key=lambda item:item[1]))
# response:
# [('age', 19), ('wangyan', 21), ('lilee', 25), ('liqun', 32)]
2、判断dict 为空条件
参考连接:https://www.jb51.net/article/149281.htm
利用not 即可判断,利用3 删除是空{}的dict 元素
for i in list(cf.keys()):
if len(list(cf[i].keys()))==0:
del cf[i]
3、修改dict 长度RuntimeError: dictionary changed size during iteration
参考连接:https://blog.csdn.net/u013344884/article/details/81867225