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

Alex Martelli aleax at
Mon Jan 9 00:29:33 EST 2006

Raymond Hettinger <python at> wrote:
> Request for more information
> ----------------------------
> My request for readers of comp.lang.python is to search your own code
> to see if map's None fill-in feature was ever used in real-world code
> (not toy examples).  I'm curious about the context, how it was used,
> and what alternatives were rejected (i.e. did the fill-in feature

I had (years ago, version was 1.5.2) one real-world case of map(max,
seq1, seq2).  The sequences represented alternate scores for various
features, using None to mean "the score for this feature cannot be
computed by the algorithm used to produce this sequence", and it was
common to have one sequence longer (using a later-developed algorithm
that computed more features).  This use may have been an abuse of my
observation that max(None, N) and max(N, None) were always N on the
platform I was using at the time.  I was relatively new at Python, and
in retrospect I feel I might have been going for "use all the new toys
we've just gotten" -- looping on feature index to compute the scores,
and explicitly testing for None, might have been a better approach than
building those lists (with seq1=map(scorer1, range(N)), btw) and then
running map on them, anyway.  At any rate, I later migrated to a lazily
computed version, don't recall the exact details but it was something
like (in today's Python):

class LazyMergedList(object):
  def __init__(self, *fs):
    self.fs = *fs
    self.known= {}
  def __getitem__(self, n):
    try: return self.known[n]
    except KeyError: pass
    result = self.known[n] = max(f(n) for f in fs)
    return result

when it turned out that in most cases the downstream code wasn't
actually using all the features (just a small subset in each case), so
computing all of them ahead of time was a waste of cycles.

I don't recall ever relying on map's None-filling feature in other
real-world cases, and, as I mentioned, even here the reliance was rather
doubtful.  OTOH, if I had easily been able to specify a different
filler, I _would_ have been able to use it a couple of times.


More information about the Python-list mailing list