выборка to_select элементов из available возможных

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def selector(to_select, available, callback):
l = []
def go_deeper():
if len(l) == to_select:
callback(l)
else:
for i in xrange(l[-1] + 1, available):
l.append(i)
go_deeper()
l.pop()
for j in xrange(0, available - to_select + 1):
l.append(j)
go_deeper()
l.pop()
def printer(l):
print l
selector(5, 36, printer)