think you want http://docs.python.org/2/library/itertools.html#itertools.product