Created
December 4, 2012 07:01
-
-
Save yueyoum/4201407 to your computer and use it in GitHub Desktop.
Python random.shuffle test. Python random 模块 中的 shuffle 测试
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | |
for x1, x2 in xx: | |
print x1, '\t', | |
for _x in x2: | |
print _x, '\t', | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment