Re: iterator question

2009-04-02 Thread Aaron Brady
On Apr 2, 5:17 pm, grocery_stocker wrote: > On Apr 2, 3:14 pm, grocery_stocker wrote: > > Discussion subject changed to "iterator question" by grocery_stocker Well, I thought it was funny. 'iteratoration'. Next, conversateration? -- http://mail.python.org/mailman/listinfo/python-list

Re: iterator question

2009-04-02 Thread Erik Max Francis
grocery_stocker wrote: How come when I call some_func().next(), the counter doesn't get incremented? Because you're creating a new instance each time you call it. Each new instance starts with 0. But when I call iterator.next(), it does. That's because you're iterating over a single obje

Re: iterator question

2006-09-29 Thread Travis Oliphant
Neal Becker wrote: > Any suggestions for transforming the sequence: > > [1, 2, 3, 4...] > Where 1,2,3.. are it the ith item in an arbitrary sequence > > into a succession of tuples: > > [(1, 2), (3, 4)...] > > In other words, given a seq and an integer that specifies the size of tuple > to retu

Re: iterator question

2006-09-27 Thread [EMAIL PROTECTED]
Er, whoops. That would work if the last item in the list was 10 (and, of course, this doesn't work for any arbitrary sequence). Is there any "look-ahead" function for list comprehensions? Danny [EMAIL PROTECTED] wrote: > Simple list comprehension? > > >>> l = [1,2,3,4,5,6,7,8,9,0] > >>> [(x, x+

Re: iterator question

2006-09-27 Thread [EMAIL PROTECTED]
Simple list comprehension? >>> l = [1,2,3,4,5,6,7,8,9,0] >>> [(x, x+1) for x in l if x%2 == 1] [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)] Danny Neal Becker wrote: > George Sakkis wrote: > > > [EMAIL PROTECTED] wrote: > > > >> def transform(seq, size): > >> i = 0 > >> while i < len(seq): >

Re: iterator question

2006-09-27 Thread Neal Becker
George Sakkis wrote: > [EMAIL PROTECTED] wrote: > >> def transform(seq, size): >> i = 0 >> while i < len(seq): >> yield tuple(seq[i:i+size]) >> i += size > > Or for arbitrary iterables, not just sequences: > > from itertools import islice > def transform(iterable, size):

Re: iterator question

2006-09-26 Thread George Sakkis
Steve Holden wrote: > George Sakkis wrote: > > Neil Cerutti wrote: > > > > > >>On 2006-09-26, Neal Becker <[EMAIL PROTECTED]> wrote: > >> > >>>Any suggestions for transforming the sequence: > >>> > >>>[1, 2, 3, 4...] > >>>Where 1,2,3.. are it the ith item in an arbitrary sequence > >>> > >>>into a

Re: iterator question

2006-09-26 Thread Rob Williscroft
Rob Williscroft wrote in news:Xns984ACDA635C9rtwfreenetREMOVEcouk@ 216.196.109.145 in comp.lang.python: seq = range(11) zip(seq[::2], seq[1::2] + [None]) > [(0, 1), (2, 3), (4, 5), (6, 7), (8, 9), (10, None)] > seq = range(10) zip(seq[::2], seq[1::2] + [None]) > [(0, 1), (2, 3

Re: iterator question

2006-09-26 Thread Rob Williscroft
Neal Becker wrote in news:[EMAIL PROTECTED] in comp.lang.python: > Any suggestions for transforming the sequence: > > [1, 2, 3, 4...] > Where 1,2,3.. are it the ith item in an arbitrary sequence > > into a succession of tuples: > > [(1, 2), (3, 4)...] > > In other words, given a seq and an in

Re: iterator question

2006-09-26 Thread Bruno Desthuilliers
Neal Becker a écrit : > Any suggestions for transforming the sequence: > > [1, 2, 3, 4...] > Where 1,2,3.. are it the ith item in an arbitrary sequence > > into a succession of tuples: > > [(1, 2), (3, 4)...] > > In other words, given a seq and an integer that specifies the size of tuple > to r

Re: iterator question

2006-09-26 Thread Steve Holden
George Sakkis wrote: > Neil Cerutti wrote: > > >>On 2006-09-26, Neal Becker <[EMAIL PROTECTED]> wrote: >> >>>Any suggestions for transforming the sequence: >>> >>>[1, 2, 3, 4...] >>>Where 1,2,3.. are it the ith item in an arbitrary sequence >>> >>>into a succession of tuples: >>> >>>[(1, 2), (3,

Re: iterator question

2006-09-26 Thread Boris Borcic
Neal Becker wrote: > Any suggestions for transforming the sequence: > > [1, 2, 3, 4...] > Where 1,2,3.. are it the ith item in an arbitrary sequence > > into a succession of tuples: > > [(1, 2), (3, 4)...] > > In other words, given a seq and an integer that specifies the size of tuple > to retu

Re: iterator question

2006-09-26 Thread George Sakkis
Neil Cerutti wrote: > On 2006-09-26, Neal Becker <[EMAIL PROTECTED]> wrote: > > Any suggestions for transforming the sequence: > > > > [1, 2, 3, 4...] > > Where 1,2,3.. are it the ith item in an arbitrary sequence > > > > into a succession of tuples: > > > > [(1, 2), (3, 4)...] > > > > In other wo

Re: iterator question

2006-09-26 Thread Neil Cerutti
On 2006-09-26, Neal Becker <[EMAIL PROTECTED]> wrote: > Any suggestions for transforming the sequence: > > [1, 2, 3, 4...] > Where 1,2,3.. are it the ith item in an arbitrary sequence > > into a succession of tuples: > > [(1, 2), (3, 4)...] > > In other words, given a seq and an integer that specif

Re: iterator question

2006-09-26 Thread George Sakkis
[EMAIL PROTECTED] wrote: > def transform(seq, size): > i = 0 > while i < len(seq): > yield tuple(seq[i:i+size]) > i += size Or for arbitrary iterables, not just sequences: from itertools import islice def transform(iterable, size): it = iter(iterable) while True

Re: iterator question

2006-09-26 Thread John Hicken
Neal Becker wrote: > Any suggestions for transforming the sequence: > > [1, 2, 3, 4...] > Where 1,2,3.. are it the ith item in an arbitrary sequence > > into a succession of tuples: > > [(1, 2), (3, 4)...] > > In other words, given a seq and an integer that specifies the size of tuple > to return,

Re: iterator question

2006-09-26 Thread johnzenger
def transform(seq, size): i = 0 while i < len(seq): yield tuple(seq[i:i+size]) i += size Neal Becker wrote: > Any suggestions for transforming the sequence: > > [1, 2, 3, 4...] > Where 1,2,3.. are it the ith item in an arbitrary sequence > > into a succession of tuples: > >