from random import randint
from collections import OrderedDict
from time import time
ordered_dict = OrderedDict()
players = list('ABCDEFGHI')
start_second = time()
for i in range(9) :
input()
p = players.pop(randint(0, 8-i))
end_second = time()
print(i+1, p, end_second - start_second)
ordered_dict[p] = (i + 1, end_second - start_second)
print(ordered_dict)
运行结果:
OrderedDict([
('E', (1, 1.6347525119781494)),
('A', (2, 2.6136345863342285)),
('G', (3, 3.304358959197998)),
('B', (4, 4.102595329284668)),
('D', (5, 4.8459577560424805)),
('H', (6, 5.447840213775635)),
('I', (7, 6.3935933113098145)),
('C', (8, 7.570738315582275)),
('F', (9, 8.239575147628784))])
最后
以上就是无奈翅膀最近收集整理的关于Python——保持字典的有序性的全部内容,更多相关Python——保持字典内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复