[Numpy-discussion] combinatorics

Sam Tygier Sam.Tygier at hep.manchester.ac.uk
Thu Mar 4 06:20:22 EST 2010


itertools in the python standard library has what you need

>>> import itertools
>>> list( itertools.product([4,5], [7,8,9]) )
[(4, 7), (4, 8), (4, 9), (5, 7), (5, 8), (5, 9)]

(all the itertools functions return generators, so the list() is to
convert it to a list)

Sam




More information about the NumPy-Discussion mailing list