To create a list from 1 to y
, use range(1, y+1)
. With this knowledge, it should be pretty straightforward to take your current itertools
knowledge and apply it to the problem:
import itertools
print list(itertools.combinations(range(1, y+1), x))
To get each result as a list instead of a tuple, you can use a list comprehension:
print [list(x) for x in itertools.combinations(range(1, y+1), x)]
Or an alternative using map()
:
print map(list, itertools.combinations(range(1, y+1), x))