Welcome, guest | Sign In | My Account | Store | Cart
def sparsify(d):
    """Improve dictionary sparsity.

    The dict.update() method makes space for non-overlapping keys.
    Giving it a dictionary with 100% overlap will build the same
    dictionary in the larger space.  The resulting dictionary will
    be no more that 1/3 full.  As a result, lookups require less
    than 1.5 probes on average.

    >>> import __builtin__
    >>> sparsify(__builtin__.__dict__)


    e = d.copy()


  • revision 3 (19 years ago)
  • previous revisions are not available