I was looking for a python k-combination algorithm and found this little beauty here https://stackoverflow.com/a/2837693/553383
Any idea about its T(n) and/or time complexity?
Here is the code that you'll find in above link:
def choose_iter(elements, length):
for i in xrange(len(elements)):
if length == 1:
yield (elements[i],)
else:
for next in choose_iter(elements[i+1:len(elements)], length-1):
yield (elements[i],) + next
def choose(l, k):
return list(choose_iter(l, k))