can list comprehensions replace map?

Peter Otten __peter__ at web.de
Fri Jul 29 14:27:18 EDT 2005


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] -= 1
>              while countactive[0]:
>                  yield None
>          seqs = [itertools.chain(seq, Nones()) for seq in seqs]
>          return itertools.izip(*seqs)

You may be introducing a lot of extra tests in the while loop with the
non-constant condition -- which in practice is fairly cheap, though. 
I'm willing to take the performance hit for the introduction of sane
variable names alone...

Peter



More information about the Python-list mailing list