import random
k = random.sample(xrange(0x41, 0x5b), 26)
print k
import random k = random.sample(xrange(0x41, 0x5b), 26) print k k = [chr(x) for x in k] print k v = random.sample(xrange(1000000), 26) print v d = dict(zip(k, v)) print d
输出结果
</pre><pre name="code" class="python">[75, 85, 78, 71, 65, 76, 73, 77, 84, 66, 80, 83, 81, 86, 89, 82, 69, 72, 88, 67, 70, 68, 90, 87, 74, 79] ['K', 'U', 'N', 'G', 'A', 'L', 'I', 'M', 'T', 'B', 'P', 'S', 'Q', 'V', 'Y', 'R', 'E', 'H', 'X', 'C', 'F', 'D', 'Z', 'W', 'J', 'O'] [327851, 563346, 164777, 107520, 876234, 166741, 770022, 158943, 496760, 706562, 468265, 896602, 386906, 981576, 571990, 685974, 931646, 549683, 387337, 952350, 447024, 427805, 640073, 496475, 629475, 827474] {'A': 876234, 'C': 952350, 'B': 706562, 'E': 931646, 'D': 427805, 'G': 107520, 'F': 447024, 'I': 770022, 'H': 549683, 'K': 327851, 'J': 629475, 'M': 158943, 'L': 166741, 'O': 827474, 'N': 164777, 'Q': 386906, 'P': 468265, 'S': 896602, 'R': 685974, 'U': 563346, 'T': 496760, 'W': 496475, 'V': 981576, 'Y': 571990, 'X': 387337, 'Z': 640073}