homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients rhettinger, tim.peters
Date 2013年05月08日.20:48:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1368046100.27.0.459086257324.issue17930@psf.upfronthosting.co.za>
In-reply-to
Content
There's another savings to be had when an index becomes the maximum: in that case, all the indices to its right are already at the maximum, so no need to overwrite them. This isn't as big a savings as skipping the search, but still buys about 10% more in the Python code. Like so:
 def cwr3(iterable, r):
 pool = tuple(iterable)
 n = len(pool)
 if n == 0 and r:
 return
 indices = [0] * r
 yield tuple(pool[i] for i in indices)
 rmax, nmax = r-1, n-1
 j = rmax if n > 1 else -1
 while j >= 0:
 newval = indices[j] + 1
 if newval < nmax:
 indices[j:] = [newval] * (r - j)
 j = rmax
 else:
 assert newval == nmax
 indices[j] = newval
 j -= 1
 yield tuple(pool[i] for i in indices)
History
Date User Action Args
2013年05月08日 20:48:20tim.peterssetrecipients: + tim.peters, rhettinger
2013年05月08日 20:48:20tim.peterssetmessageid: <1368046100.27.0.459086257324.issue17930@psf.upfronthosting.co.za>
2013年05月08日 20:48:20tim.peterslinkissue17930 messages
2013年05月08日 20:48:20tim.peterscreate

AltStyle によって変換されたページ (->オリジナル) /