import random mydeck = [r+s for r in '23456789TJQKA' for s in 'SHDC'] def deal(numhands, n=5, deck=mydeck) random.shuffle(deck) return [deck[n*i:n*(i+1)] for i in range(numhands)]
def hand_percentages(n=700*1000): "sample n random hands and print a table of percentages for each type of hand." counts = [0] * 9 for i in range(n/10): for hand in deal(10): ranking = hand_rank(hand)[0] counts[ranking] += 1 for i in reversed(range(9)): print "%14s: %6.3f %%" % (hand_names[i], 100.*counts[i]/n)
def shuffle1(deck): N = len(deck) swapped = [False] * N while not all(swapped) i, j = random.randrange(N), random.randrange(N) swapped[i] = swapped[j] = True swap(deck, i, j) def swap(deck, i, j): print 'swap', i, j deck[i], deck[j] = deck[j], deck[i]
utas = ['Peter', 'Andy', 'Sarah', 'Gundega', 'Job', 'Sean'] uppercasetas = [name.upper() for name in utas] print uppercasetas