Christopher Subich wrote:
My naive solution:
...
for i in ilist:
try:
g = i.next()
count += 1
except StopIteration: # End of iter
g = None
...
What I didn't like about this was the extra overhead of all
the
Andrew Dalke wrote:
Steven Bethard wrote:
Here's one possible solution:
py import itertools as it
py def zipfill(*lists):
... max_len = max(len(lst) for lst in lists)
A limitation to this is the need to iterate over the
lists twice, which might not be possible if one of them
is a
Peter Otten wrote:
Combining your clever and your elegant approach to something fast
(though I'm not entirely confident it's correct):
def fillzip(*seqs):
def done_iter(done=[len(seqs)]):
done[0] -= 1
if not done[0]:
return
while 1:
Peter Otten wrote:
def fillzip(*seqs):
def done_iter(done=[len(seqs)]):
done[0] -= 1
if not done[0]:
return
while 1:
yield None
seqs = [chain(seq, done_iter()) for seq in seqs]
return izip(*seqs)
Can I play too? How about:
Andrew Dalke wrote:
Peter Otten wrote:
Combining your clever and your elegant approach to something fast
(though I'm not entirely confident it's correct):
def fillzip(*seqs):
def done_iter(done=[len(seqs)]):
done[0] -= 1
if not done[0]:
return
Me:
Could make it one line shorter with
from itertools import chain, izip, repeat
def fillzip(*seqs):
def done_iter(done=[len(seqs)]):
done[0] -= 1
if not done[0]:
return []
return repeat(None)
seqs = [chain(seq, done_iter()) for seq in seqs]
Scott David Daniels wrote:
Can I play too? How about:
Sweet!
Andrew
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
Andrew Dalke wrote:
Me:
Could make it one line shorter with
from itertools import chain, izip, repeat
def fillzip(*seqs):
def done_iter(done=[len(seqs)]):
done[0] -= 1
if not done[0]:
return []
return repeat(None)
seqs = [chain(seq,
Scott David Daniels wrote:
Can I play too?
Not unless you buy the expensive but good-looking c.l.py gaming license
which is only available trough me :)
How about:
import itertools
def fillzip(*seqs):
def Nones(countactive=[len(seqs)]):
countactive[0] -=
Peter Otten wrote:
Seems my description didn't convince you. So here's an example:
Got it. In my test case the longest element happened to be the last
one, which is why it didn't catch the problem.
Thanks.
Andrew
[EMAIL
Steven Bethard wrote:
Here's one possible solution:
py import itertools as it
py def zipfill(*lists):
... max_len = max(len(lst) for lst in lists)
A limitation to this is the need to iterate over the
lists twice, which might not be possible if one of them
is a file iterator.
Here's a
Andrew Dalke wrote:
Steven Bethard wrote:
Here's one possible solution:
py import itertools as it
py def zipfill(*lists):
... max_len = max(len(lst) for lst in lists)
A limitation to this is the need to iterate over the
lists twice, which might not be possible if one of them
is a file
Newbie question:
I have been generally open to the proposal that list comprehensions
should replace 'map', but I ran into a need for something like
map(None,x,y)
when len(x)len(y). I cannot it seems use 'zip' because I'll lose
info from x. How do I do this as a list comprehension? (Or,
more
David Isaac wrote:
Newbie question:
I have been generally open to the proposal that list comprehensions
should replace 'map', but I ran into a need for something like
map(None,x,y)
when len(x)len(y). I cannot it seems use 'zip' because I'll lose
info from x. How do I do this as a list
Michael Hoffman wrote:
David Isaac wrote:
Newbie question:
I have been generally open to the proposal that list comprehensions
should replace 'map', but I ran into a need for something like
map(None,x,y)
when len(x)len(y). I cannot it seems use 'zip' because I'll lose
info from x. How
This isn't really a question about list
comprehensions as you are using a feature
of map by passing None as the function to be
executed over each list element:
This works when len(x) len(y):
zip(x,y+(len(x)-len(y))*[None])
This works when len(y) =0 len(x):
zip(x+(len(x)-len(y))*[None],y)
I
David Isaac wrote:
Newbie question:
I have been generally open to the proposal that list comprehensions
should replace 'map', but I ran into a need for something like
map(None,x,y)
when len(x)len(y). I cannot it seems use 'zip' because I'll lose
info from x. How do I do this as a list
David Isaac wrote:
I have been generally open to the proposal that list comprehensions
should replace 'map', but I ran into a need for something like
map(None,x,y)
when len(x)len(y). I cannot it seems use 'zip' because I'll lose
info from x. How do I do this as a list comprehension? (Or,
[David Isaac]
I have been generally open to the proposal that list comprehensions
should replace 'map', but I ran into a need for something like
map(None,x,y)
when len(x)len(y). I cannot it seems use 'zip' because I'll lose
info from x. How do I do this as a list comprehension? (Or,
David Isaac wrote:
I ran into a need for something like map(None,x,y)
when len(x)len(y). I cannot it seems use 'zip' because I'll lose
info from x.
I almost never run into this situation, so I'd be interested to know why
you need this. Here's one possible solution:
py import itertools as
Raymond Hettinger wrote:
[David Isaac]
I have been generally open to the proposal that list comprehensions
should replace 'map', but I ran into a need for something like
map(None,x,y)
when len(x)len(y). I cannot it seems use 'zip' because I'll lose
info from x. How do I do this as a list
21 matches
Mail list logo