范围[-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), (-794, 1), (-784, 1), (-771, 1), (-766, 1), (-753, 2), (-745, 1), (-720, 1), (-715, 2), (-671, 1), (-669, 1), (-656, 1), (-635, 1), (-628, 1), (-625, 1), (-613, 1), (-609, 1), (-587, 1), (-569, 1), (-555, 1), (-506, 1), (-500, 1), (-460, 1), (-413, 1), (-405, 1), (-402, 1), (-384, 2), (-359, 1), (-315, 1), (-301, 1), (-251, 1), (-202, 1), (-191, 1), (-172, 1), (-149, 1), (-145, 1), (-102, 1), (-99, 1), (-72, 1), (-65, 1), (-13, 1), (-2, 1), (27, 1), (57, 1), (85, 1), (124, 1), (164, 1), (177, 1), (184, 1), (223, 1), (244, 1), (252, 1), (261, 1), (263, 1), (350, 1), (365, 1), (389, 1), (416, 2), (424, 1), (426, 1), (436, 1), (438, 1), (449, 2), (461, 1), (549, 2), (558, 1), (566, 1), (569, 1), (622, 1), (624, 1), (630, 1), (794, 1), (815, 1), (820, 1), (852, 1), (885, 1), (895, 1), (909, 1), (916, 1), (934, 1), (957, 1), (973, 1), (976, 1), (999, 1)])