can list comprehensions replace map?

Scott David Daniels Scott.Daniels at Acm.Org
Fri Jul 29 19:05:27 CEST 2005


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:
     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)

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list