Skip to content

Instantly share code, notes, and snippets.

@yueyoum
Created December 4, 2012 07:01
Show Gist options
  • Save yueyoum/4201407 to your computer and use it in GitHub Desktop.
Save yueyoum/4201407 to your computer and use it in GitHub Desktop.
Python random.shuffle test. Python random 模块 中的 shuffle 测试
import random
import sys
import copy
import pprint
seq = [chr(i) for i in range(ord('A'), ord('A') + 10)]
times = int(sys.argv[1])
result = {}
for s in seq:
result[s] = {}
for i in range(times):
random.shuffle(seq)
for c in result:
for index, s in enumerate(seq):
if c == s:
t = 1
else:
t = 0
result[c][index] = result[c].get(index, 0) + t
#pprint.pprint(result)
rr = {}
for k, v in result.items():
v = v.items()
v.sort(key=lambda a: a[0])
rr[k] = [a[1] for a in v]
xx = rr.items()
xx.sort(key=lambda a:[0])
print
print
for x1, x2 in xx:
print x1, '\t',
for _x in x2:
print _x, '\t',
print
print
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment