Le Fri, 28 Jan 2005 13:59:45 GMT, Chris Wright a écrit :
> Hi,
>
> 1) I want to iterate over a list "N at a time"
>
>
> Is there a nifty way to do with with list comprehensions,
> or do I just have to loop over the list ?
>
> cheers and thanks
seq = xrange(1, 9) # an iterable [1, 2, ... 8]
N = 2
it = (iter(seq,)*N # a tuple containing N times the *same* iterator on
seq
print zip(*it) # the list you are after
from itertools import izip
help(izip)
it = (iter(seq),)*2
for tup in izip(*it):
print tup
>
> chris wright
--
http://mail.python.org/mailman/listinfo/python-list