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
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
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
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+
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):
>
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):
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
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
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
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
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,
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
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
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
[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
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,
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:
>
>
17 matches
Mail list logo