Re: generate tuples from sequence

2007-01-18 Thread Duncan Booth
Peter Otten [EMAIL PROTECTED] wrote: But still, to help my lack of fantasy -- what would a sane zip() implementation look like that does not guarantee the above output? Hypothetically? The code in zip which builds the result tuples looks (ignoring error handling) like: // inside a loop

Re: generate tuples from sequence

2007-01-18 Thread Peter Otten
Duncan Booth wrote: Peter Otten [EMAIL PROTECTED] wrote: But still, to help my lack of fantasy -- what would a sane zip() implementation look like that does not guarantee the above output? Hypothetically? The code in zip which builds the result tuples looks (ignoring error handling)

Re: generate tuples from sequence

2007-01-18 Thread Duncan Booth
Peter Otten [EMAIL PROTECTED] wrote: Let's see if I understand the above: In C a call f(g(), g()) may result in machine code equivalent to either x = g() y = g() f(x, y) or y = g() x = g() f(x, y) Is that it? Yes, or changing one of the calls to h() and compiling with

generate tuples from sequence

2007-01-17 Thread Will McGugan
Hi, I'd like a generator that takes a sequence and yields tuples containing n items of the sqeuence, but ignoring the 'odd' items. For example take_group(range(9), 3) - (0,1,2) (3,4,5) (6,7,8) This is what I came up with.. def take_group(gen, count): i=iter(gen) while True:

Re: generate tuples from sequence

2007-01-17 Thread Will McGugan
Will McGugan wrote: Hi, I'd like a generator that takes a sequence and yields tuples containing n items of the sqeuence, but ignoring the 'odd' items. For example Forgot to add, for my purposes I will always have a sequence with a multiple of n items. Will --

Re: generate tuples from sequence

2007-01-17 Thread Peter Otten
Will McGugan wrote: I'd like a generator that takes a sequence and yields tuples containing n items of the sqeuence, but ignoring the 'odd' items. For example take_group(range(9), 3) - (0,1,2) (3,4,5) (6,7,8) I like items = range(9) N = 3 zip(*[iter(items)]*N) [(0, 1, 2), (3, 4, 5), (6,

Re: generate tuples from sequence

2007-01-17 Thread Tim Williams
On 17 Jan 2007 04:50:33 -0800, Will McGugan [EMAIL PROTECTED] wrote: Will McGugan wrote: Hi, I'd like a generator that takes a sequence and yields tuples containing n items of the sqeuence, but ignoring the 'odd' items. For example Forgot to add, for my purposes I will always have a

Re: generate tuples from sequence

2007-01-17 Thread Neil Cerutti
On 2007-01-17, Will McGugan [EMAIL PROTECTED] wrote: Hi, I'd like a generator that takes a sequence and yields tuples containing n items of the sqeuence, but ignoring the 'odd' items. For example take_group(range(9), 3) - (0,1,2) (3,4,5) (6,7,8) This is what I came up with.. def

Re: generate tuples from sequence

2007-01-17 Thread M�ta-MCI
Hi! r=iter(range(9)) print zip(r,r,r) But, it's few like Peter... -- Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list

Re: generate tuples from sequence

2007-01-17 Thread Alan Isaac
Peter Otten [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I like items = range(9) N = 3 zip(*[iter(items)]*N) [(0, 1, 2), (3, 4, 5), (6, 7, 8)] Except that it is considered implementation dependent: http://mail.python.org/pipermail/python-list/2005-February/307550.html Alan

Re: generate tuples from sequence

2007-01-17 Thread Peter Otten
Alan Isaac wrote: Peter Otten [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I like items = range(9) N = 3 zip(*[iter(items)]*N) [(0, 1, 2), (3, 4, 5), (6, 7, 8)] Except that it is considered implementation dependent: