Re: itertools question

2009-05-15 Thread pataphor
Neal Becker wrote: Is there any canned iterator adaptor that will transform: in = [1,2,3] into: out = [(1,2,3,4), (5,6,7,8),...] That is, each time next() is called, a tuple of the next N items is returned. Here's one that abuses a for loop: from itertools import islice def grouper(

Re: itertools question

2009-05-14 Thread Lie Ryan
Chris Rebert wrote: They really should just add grouper() to itertools rather than leaving it as a recipe. People keep asking for it so often... I've just added it to the issue tracker: http://bugs.python.org/issue6021 -- http://mail.python.org/mailman/listinfo/python-list

Re: itertools question

2009-05-14 Thread Chris Rebert
On Thu, May 14, 2009 at 8:53 AM, Ned Deily wrote: > In article , >  Neal Becker wrote: >> Is there any canned iterator adaptor that will >> >> transform: >> in = [1,2,3] >> >> into: >> out = [(1,2,3,4), (5,6,7,8),...] >> >> That is, each time next() is called, a tuple of the next N items is >

Re: itertools question

2009-05-14 Thread Ned Deily
In article , Neal Becker wrote: > Is there any canned iterator adaptor that will > > transform: > in = [1,2,3] > > into: > out = [(1,2,3,4), (5,6,7,8),...] > > That is, each time next() is called, a tuple of the next N items is > returned. This topic was discussed here just a few days a

Re: itertools question

2009-05-14 Thread Lie Ryan
Neal Becker wrote: Is there any canned iterator adaptor that will transform: in = [1,2,3] into: out = [(1,2,3,4), (5,6,7,8),...] That is, each time next() is called, a tuple of the next N items is returned. An option, might be better since it handles infinite list correctly: >>>

Re: itertools question

2009-05-14 Thread Peter Otten
Neal Becker wrote: > Is there any canned iterator adaptor that will > > transform: > in = [1,2,3] > > into: > out = [(1,2,3,4), (5,6,7,8),...] > > That is, each time next() is called, a tuple of the next N items is > returned. Depending on what you want to do with items that don't make a c

Re: itertools question

2009-05-14 Thread Nick Craig-Wood
Neal Becker wrote: > Is there any canned iterator adaptor that will > > transform: > in = [1,2,3] > > into: > out = [(1,2,3,4), (5,6,7,8),...] > > That is, each time next() is called, a tuple of the next N items is > returned. This is my best effort... not using itertools as my br

Re: itertools question

2009-05-14 Thread Glauco
Neal Becker ha scritto: Is there any canned iterator adaptor that will transform: in = [1,2,3] into: out = [(1,2,3,4), (5,6,7,8),...] That is, each time next() is called, a tuple of the next N items is returned. http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-

itertools question

2009-05-14 Thread Neal Becker
Is there any canned iterator adaptor that will transform: in = [1,2,3] into: out = [(1,2,3,4), (5,6,7,8),...] That is, each time next() is called, a tuple of the next N items is returned. -- http://mail.python.org/mailman/listinfo/python-list

Re: Itertools question: how to call a function n times?

2007-07-19 Thread jrbj
On Jul 19, 8:35 am, Matthew Wilson <[EMAIL PROTECTED]> wrote: > I want to write a function that each time it gets called, it returns a > random choice of 1 to 5 words from a list of words. > > I can write this easily using for loops and random.choice(wordlist) and > random.randint(1, 5). > > But I

Re: Itertools question: how to call a function n times?

2007-07-19 Thread Stargaming
Matthew Wilson schrieb: > I want to write a function that each time it gets called, it returns a > random choice of 1 to 5 words from a list of words. > > I can write this easily using for loops and random.choice(wordlist) and > random.randint(1, 5). > > But I want to know how to do this using it

Re: Itertools question: how to call a function n times?

2007-07-19 Thread Wojciech Muła
Matthew Wilson wrote: > I want to write a function that each time it gets called, it returns a > random choice of 1 to 5 words from a list of words. > > I can write this easily using for loops and random.choice(wordlist) and > random.randint(1, 5). > > But I want to know how to do this using iterto

Re: Itertools question: how to call a function n times?

2007-07-19 Thread Bruno Desthuilliers
Matthew Wilson a écrit : > I want to write a function that each time it gets called, it returns a > random choice of 1 to 5 words from a list of words. > > I can write this easily using for loops and random.choice(wordlist) and > random.randint(1, 5). > > But I want to know how to do this using i

Itertools question: how to call a function n times?

2007-07-19 Thread Matthew Wilson
I want to write a function that each time it gets called, it returns a random choice of 1 to 5 words from a list of words. I can write this easily using for loops and random.choice(wordlist) and random.randint(1, 5). But I want to know how to do this using itertools, since I don't like manually d