[Python-ideas] itertools.documentation.ncycles is a bit of a sore thumb

Julian Berman julian at grayvines.com
Wed Aug 3 15:39:39 CEST 2011

The top of the recipe section in the itertools documentation says:

"The superior memory performance is kept by processing elements one at a time rather than bringing the whole iterable into memory all at once."

but itertools.ncycles doesn't really. It's one line, so I'll inline it here:

def ncycles(iterable, n):
  return chain.from_iterable(repeat(tuple(iterable), n))

Somewhere along the line something was going to need to buffer that, but it'd be nicer if the example didn't have the buffering done all at once at the outset as it is now.

Perhaps more importantly, though, is there a specific objection to just adding a count to itertools.cycle much like itertools.repeat has now for this?


More information about the Python-ideas mailing list