1 2 3 4 5 6 7
import random from collections import defaultdict d = defaultdict(int) for i in xrange(10000): d[tuple(sorted((random.choice(['b','g']), random.choice(['b','g']))))] += 1 for k,v in d.items(): print k,v
1 2 3
('b', 'b') 2508 ('b', 'g') 4986 ('g', 'g') 2506