from random import randint
from collections import OrderedDict
from time import time
# 创建有序字典
d = OrderedDict()
plays = list('ABCDEFGH')
start = time()
for i in range(8):
input() # 每次输入停顿,制造顺序
p = plays.pop(randint(0,7 - i))
end = time()
print(i + 1,p,end-start)
d[p] = (i+1,p,end-start)
print('----------------')
# 遍历有序字典
for p in d:
print(p,d[p])
python3 50个练习例子之让字典保持有序
最新推荐文章于 2024-04-10 23:09:35 发布