范围[-1000,1000]
from collections import OrderedDict
import random
lst = sorted([(random.randint(-1000,1000))for i in range(100)])
print(lst,end='\n\n')
od = OrderedDict()
for k in lst:
od.setdefault(k,0)
od[k] += 1
print(od)
运行结果:
[-988, -982, -976, -971, -964, -930, -884, -871, -825, -810, -809, -794, -784, -771, -766, -753, -753, -745, -720, -715, -715, -671, -669, -656, -635, -628, -625, -613, -609, -587, -569, -555, -506, -500, -460, -413, -405, -402, -384, -384, -359, -315, -301, -251, -202, -191, -172, -149, -145, -102, -99, -72, -65, -13, -2, 27, 57, 85, 124, 164, 177, 184, 223, 244, 252, 261, 263, 350, 365, 389, 416, 416, 424, 426, 436, 438, 449, 449, 461, 549, 549, 558, 566, 569, 622, 624, 630, 794, 815, 820, 852, 885, 895, 909, 916, 934, 957, 973, 976, 999]
OrderedDict([(-988, 1), (-982, 1), (-976, 1), (-971, 1), (-964, 1), (-930, 1), (-884, 1), (-871, 1), (-825, 1), (-810, 1), (-809, 1