There are two non-negative integers min and max , max > min , as well as a positive integer n . It is necessary to obtain all possible sets of the form S={x1, ..., xn} , where min<x1<...<xn<max .

For example, for n=3, min=0, max=5 you need to get {1,2,3} , {1,2,4} , {1,3,4} , {2,3,4} .

Can python have a special function for this? If not, then the algorithm is enough.

    2 answers 2

     from itertools import combinations n=3 my_min=0 my_max=5 [comb for comb in combinations(xrange(my_min+1, my_max-1), n)] 
    • Yes, thanks, already figured out - max

    It seems to have found a solution:

     print(list(itertools.combinations(range(min+1, max-1), n)))