如果你要对一组数据进行查找,请使用字典!
真的好用!
1. 统计个数
示例:统计每个id出现次数
count={}
if id in count:
count[id] += 1 #id可以为整数或字符串
else:
count[id] = 1
2. 按值排序
count2=sorted(count.items(),key=lambda e:e[1])
如果你要对一组数据进行查找,请使用字典!
真的好用!
示例:统计每个id出现次数
count={}
if id in count:
count[id] += 1 #id可以为整数或字符串
else:
count[id] = 1
count2=sorted(count.items(),key=lambda e:e[1])