[Python-Dev] dict.supplement() (was Re: list.shift())

Fred L. Drake, Jr. fdrake@acm.org
Mon, 20 Mar 2000 14:02:48 -0500 (EST)

Peter Funk writes:
 > Ouppss... I should have tested this before posting.  But currently I use 
 > the more explicit (and probably slower version) in my code:

  The performance is based entirely on the size of each; in the
(probably typical) case of smallish dictionaries (<50 entries), it's
probably cheaper to use a temporary dict and do the update.
  For large dicts (on the defaults side), it may make more sense to
reduce the number of objects that need to be created:

       target = ...
       has_key = target.has_key
       for key in defaults.keys():
           if not has_key(key):
               target[key] = defaults[key]

  This saves the construction of len(defaults) 2-tuples.


Fred L. Drake, Jr.	  <fdrake at acm.org>
Corporation for National Research Initiatives