Re: can list comprehensions replace map?

2005-07-29 Thread Andrew Dalke
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

Re: can list comprehensions replace map?

2005-07-29 Thread Peter Otten
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

Re: can list comprehensions replace map?

2005-07-29 Thread Andrew Dalke
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:

Re: can list comprehensions replace map?

2005-07-29 Thread Scott David Daniels
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:

Re: can list comprehensions replace map?

2005-07-29 Thread Peter Otten
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

Re: can list comprehensions replace map?

2005-07-29 Thread Andrew Dalke
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]

Re: can list comprehensions replace map?

2005-07-29 Thread Andrew Dalke
Scott David Daniels wrote: Can I play too? How about: Sweet! Andrew [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: can list comprehensions replace map?

2005-07-29 Thread Peter Otten
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,

Re: can list comprehensions replace map?

2005-07-29 Thread Peter Otten
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] -=

Re: can list comprehensions replace map?

2005-07-29 Thread Andrew Dalke
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

Re: can list comprehensions replace map?

2005-07-28 Thread Andrew Dalke
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

Re: can list comprehensions replace map?

2005-07-28 Thread Christopher Subich
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

can list comprehensions replace map?

2005-07-27 Thread David Isaac
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

Re: can list comprehensions replace map?

2005-07-27 Thread Michael Hoffman
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

Re: can list comprehensions replace map?

2005-07-27 Thread Michael Hoffman
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

Re: can list comprehensions replace map?

2005-07-27 Thread Larry Bates
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

Re: can list comprehensions replace map?

2005-07-27 Thread Paolino
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

Re: can list comprehensions replace map?

2005-07-27 Thread Andrew Dalke
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,

Re: can list comprehensions replace map?

2005-07-27 Thread Raymond Hettinger
[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,

Re: can list comprehensions replace map?

2005-07-27 Thread Steven Bethard
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

Re: can list comprehensions replace map?

2005-07-27 Thread Paolino
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