You can use itertools.product , which is just a convenient feature for nested iterations. It also has a repeat argument if you want to repeat the same iterable several times:
>>> from itertools import product >>> amin = 0 >>> amax = 2 >>> list(product(range(amin, amax), repeat=3)) [(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)]
To get list of list , you can use map :
>>> list(map(list, product(range(amin, amax), repeat=3))) [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]
However, product is an iterator, so it is really efficient if you just iterate over it and not send it to list . At least if possible in your program. For instance:
>>> for prod in product(range(amin, amax), repeat=3): ... print(prod)