1. 随机生成10000个100以内的正整数,找出其中出现次数最多的10个数及其出现次数。
random.randint(1,10) 产生 1 到 10 的一个整数型随机数
Counter(计数器):用于追踪值的出现次数 (以字典的键值对形式存储,key为被记录数,value为被记录数的个数)
sorted(c.items(), key=lambda x: x[1]) 中 c.items() 为待排序的对象,
key=lambda x: x[1] 为对前面的对象中的第二维数据(即value)的值进行排序,key=lambda x: x[0] 是对键(key)排序。
from collections import Counter
import random
intlist = []
for x in range(1,10001):
y = random.randint(1,100)
intlist.append(y)
intListCount = Counter(intlist