Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40896

itertools doc example "consume"

Date 2013-03-08 14:28 -0600
Subject itertools doc example "consume"
From Skip Montanaro <skip@pobox.com>
Newsgroups comp.lang.python
Message-ID <mailman.3097.1362774511.2939.python-list@python.org> (permalink)

Show all headers | View raw


I've never really used itertools before.  While trying to figure out
how to break a list up into equal pieces, I came across the consume
function in the examples here:

http://docs.python.org/2/library/itertools.html

It seems to me that it should return whatever it consumes from the
list.  I thought you would call it like this:

    for chunk in consume(range(30), 5):
        print chunk

and see it print something like

[0, 1, 2, 3, 4]
[5, 6, 7, 8, 9]
...
[25, 26, 27, 28, 29]

If I call it like this:

lst = range(30)
consume(lst, 5)

it doesn't actually consume anything from lst.  Am I missing
something, or is that example missing a return or yield statement?

Thanks,

Skip

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

itertools doc example "consume" Skip Montanaro <skip@pobox.com> - 2013-03-08 14:28 -0600

csiph-web