itertools doc example "consume"

Skip Montanaro skip at pobox.com
Fri Mar 8 16:43:21 EST 2013


Ian Kelly <ian.g.kelly <at> gmail.com> writes:

> Depending on your Python version lst is either a range object or a
> list, neither of which is an iterator.  If you pass to consume an
> iterable object that is not an iterator, it will implicitly obtain an
> iterator for it, consume from the iterator, and then discard the
> iterator, with no effect on the original object.
> 
> In general the itertools functions will work equally well on iterators
> and other iterables, but consume is special in that what it does is
> only relevant to iterators.

Thanks for the explanation.  I clearly still need to grapple with this
stuff a bit...

Skip





More information about the Python-list mailing list