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
On Apr 2, 3:14 pm, grocery_stocker wrote:
> Give the following code..
>
> >>> class it:
>
> ...def __init__(self):
> ...self.count = -1
> ...def next(self):
> ...self.count +=1
> ...if self.count < 4:
> ...return self.count
> ...else:
> ...
Neal Becker writes:
> How do I interleave 2 sequences into a single sequence?
Here's a way:
>>> a = [1,2,3,4]
>>> b = [5,6,7,8]
>>> [x for S in zip(a, b) for x in S]
[1, 5, 2, 6, 3, 7, 4, 8]
> How do I interleave N sequences into a single sequence?
In the same way as above.
--
Arnaud
--
htt
Sion Arrowsmith wrote:
> Neal Becker wrote:
>>How do I interleave 2 sequences into a single sequence?
>>
>>How do I interleave N sequences into a single sequence?
>
> itertools.chain(*itertools.izip(*Nsequences))
aha! thanks. andrew
--
http://mail.python.org/mailman/listinfo/python-list
Neal Becker wrote:
>How do I interleave 2 sequences into a single sequence?
>
>How do I interleave N sequences into a single sequence?
itertools.chain(*itertools.izip(*Nsequences))
--
\S
under construction
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 2 Apr 2009, Neal Becker wrote:
> How do I interleave 2 sequences into a single sequence?
>
> How do I interleave N sequences into a single sequence?
Here's one way:
def interleave(*args):
for n in range(min(len(i) for i in args)) :
for i in args:
yield i[n]
HTH,
>>> def xl(a):
... return list(reduce(lambda x,y:x+y,zip(*a)))
...
>>> xl([[1,2],[3,4]])
[1, 3, 2, 4]
like this?
Best Regards,
-- KDr2, at x-macro.com.
On Thu, Apr 2, 2009 at 8:32 PM, Neal Becker wrote:
> How do I interleave 2 sequences into a single sequence?
>
> How do I interleave N
Neal Becker wrote:
> How do I interleave 2 sequences into a single sequence?
>
> How do I interleave N sequences into a single sequence?
don't know if there's a better way, but
from itertools import izip
def interleave(*doodahs):
for together in izip(*doodahs):
for single in together:
On Apr 2, 8:32 am, Neal Becker wrote:
> How do I interleave 2 sequences into a single sequence?
>
> How do I interleave N sequences into a single sequence?
http://lmgtfy.com/?q=python+interleave+sequences
http://code.activestate.com/recipes/511480/
http://code.activestate.com/recipes/528936/
HT
How do I interleave 2 sequences into a single sequence?
How do I interleave N sequences into a single sequence?
--
http://mail.python.org/mailman/listinfo/python-list
Thanks, Ethan. that was a great solution. i just tested it.
On Fri, May 23, 2008 at 7:08 PM, Ethan Furman <[EMAIL PROTECTED]> wrote:
> davidj411 wrote:
>
> When you save an open file to a variable, you can re-use that variable
>> for membership checking.
>> it does not seem to be that way with
On May 24, 6:36 am, davidj411 <[EMAIL PROTECTED]> wrote:
> but when i try to iterate through it again, it appears to print
> nothing (no error either). the file is exhausted?
No, the iterator is finished. Iterators are generally use-once:
"The intention of the protocol is that once an iterator's
On Fri, 23 May 2008 13:36:55 -0700, davidj411 wrote:
> example of open method on file object:
> fhandle=open(filename).readelines()
Here the name `fhandle` is somewhat misleading. You don't bind the file
object to that name, but the result of the call of the `readlines()`
method. Which is a lis
davidj411 wrote:
When you save an open file to a variable, you can re-use that variable
for membership checking.
it does not seem to be that way with the csv.reader function, even
when set to a variable name.
what is the best way to store the open CSV file in memory or do i need
to open the fil
On May 23, 3:36 pm, davidj411 <[EMAIL PROTECTED]> wrote:
> When you save an open file to a variable, you can re-use that variable
> for membership checking.
> it does not seem to be that way with the csv.reader function, even
> when set to a variable name.
>
> what is the best way to store the open
When you save an open file to a variable, you can re-use that variable
for membership checking.
it does not seem to be that way with the csv.reader function, even
when set to a variable name.
what is the best way to store the open CSV file in memory or do i need
to open the file each time?
exampl
On Apr 20, 2:05 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
>
> did you try something like (untested)
>
> cell1, cell2, cell3, cell4, cell5, \
> cell6, cell7, cell8 = row.findAll("td")
>
> No need for the "for" if you want to handle each cell differently, you
> won;t be iterating o
P:
I am screen-scraping a table. The table has an unknown number of rows,
but each row has exactly 8 cells. I would like to extract the data
from the cells, but the first three cells in each row have their data
nested inside other tags.
So I have the following code:
for row in table.findAll("tr
cjl wrote:
> P:
>
> I am screen-scraping a table. The table has an unknown number of rows,
> but each row has exactly 8 cells. I would like to extract the data
> from the cells, but the first three cells in each row have their data
> nested inside other tags.
>
> So I have the following code:
>
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:
>
>
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, then for example:
seq = [a,b,c,d,e,f
36 matches
Mail list logo