Real-world use cases for map's None fill-in feature?

Raymond Hettinger python at
Thu Jan 12 04:37:15 EST 2006

[rurpy at]
> > > How well correlated in the use of map()-with-fill with the
> > > (need for) the use of zip/izip-with-fill?

> > Close to 100%.  A non-iterator version of izip_longest() is exactly
> > equivalent to map(None, it1, it2, ...).

[rurpy at]
> If I use map()
> I can trivially determine the arguments lengths and deal with
> unequal length before map().  With iterators that is more
> difficult.  So I can imagine many cases where izip might
> be applicable but map not, and a lack of map use cases
> not representative of izip use cases.

You don't seem to understand what map() does.  There is no need  to
deal with unequal argument lengths before map(); it does the work for
you.  It handles iterator inputs the same way.  Meditate on this:

    def izip_longest(*args):
        return iter(map(None, *args))

Modulo arbitrary fill values and lazily evaluated inputs, the semantics
are exactly what is being requested.  Ergo, lack of use cases for
map(None,it1,it2) means that izip_longest(it1,it2) isn't needed.


More information about the Python-list mailing list