Simply the sample code for combinations().

This commit is contained in:
Raymond Hettinger 2008-02-27 01:44:34 +00:00
parent 2ab0552b5e
commit c105289ec4
1 changed files with 6 additions and 7 deletions

View File

@ -103,15 +103,14 @@ loops that truncate the stream.
yield tuple(pool[i] for i in vec)
while 1:
for i in reversed(range(r)):
if vec[i] == i + n-r:
continue
vec[i] += 1
for j in range(i+1, r):
vec[j] = vec[j-1] + 1
yield tuple(pool[i] for i in vec)
break
if vec[i] != i + n - r:
break
else:
return
vec[i] += 1
for j in range(i+1, r):
vec[j] = vec[j-1] + 1
yield tuple(pool[i] for i in vec)
.. versionadded:: 2.6