import sys from timeit import Timer def comb(items, n): if n==0: yield [] else: for i in xrange(len(items)): for cc in comb(items[i+1:],n-1): yield [items[i]]+cc def test(): cards = range(52) for hand in comb(cards, 5): "do something with the hand" def main(argv): t = Timer("test()", "from __main__ import test") print t.timeit(1) if __name__=="__main__": sys.exit(main(sys.argv[1:]))