This page presents a python module wrapping dicts, treaps or red-black trees (or other dictionary-like objects) to facilitate storing duplicates.

This code is known to work on CPython 2.x, CPython 3.x, Pypy 2.2 and Jython 2.7b1.

EG:

In [1]: import dupdict_mod

In [2]: dupdict = dupdict_mod.Dupdict(dict())

In [3]: for i in range(10):
   ...:     dupdict[i] = 2**i
   ...:

In [5]: list(dupdict.items())
Out[5]:
[(0, 1),
 (1, 2),
 (2, 4),
 (3, 8),
 (4, 16),
 (5, 32),
 (6, 64),
 (7, 128),
 (8, 256),
 (9, 512)]

In [6]: for i in range(3, 7):
    dupdict[i] = 3**i
   ...:

In [7]: list(dupdict.items())
Out[7]:
[(0, 1),
 (1, 2),
 (2, 4),
 (3, 8),
 (3, 27),
 (4, 16),
 (4, 81),
 (5, 32),
 (5, 243),
 (6, 64),
 (6, 729),
 (7, 128),
 (8, 256),
 (9, 512)]

You can check it out here.

See also this list of datastructures I've worked on.


Hits: 6051
Timestamp: 2024-12-22 03:32:45 PST

Back to Dan's tech tidbits

You can e-mail the author with questions or comments: