good name for a dict/list hybrid

Beni Cherniavsky cben at techunix.technion.ac.il
Tue Jan 7 14:23:15 EST 2003


On 2003-01-06, Andrew Dalke wrote:

> I have a class which I'm calling DictList.Its used for an ordered
> dictionary which can have multiple keys, though in almost all cases
> it only has single keys.It is ordered, so I want away to get an
> entry by position in the insertion order, which are integers.
>
> This means I can't use integers as keys, which is not a problem.
>
#snip
[('Name', 'Andrew'), ('PubDate', '1975 Jun'), ('Lang', 'English'),
('Name', 'Andrew Dalke')]
#snip
>
> I can't figure out what to call this thing.I chose "DictList"
> because it's a hybrid between a dictionary and a list, but that's
> a bad name since it can be confused with a dictionary of lists, or
> a list of dictionaries.
>
> This sort of data structure must be common.Eg, headers in email
> act like this.(rfc822.py provides no hints for a name.)
>
Ogg Vorbis comments also behave similarly.  The main issue to decide is
whether you care for the order between different keys.  If not, your
semantics are just an unordered mapping from keys to ordered lists of
values: {'Name': ['Andrew', 'Andrew Dalke'], 'Lang': ['English'], ...}
In that case you might be satisfied with just a dict mapping to
lists, otherwise try "DictList", "ListDict", "MultiDict", "mdict"...

If you do care for the complete order, your semantics are just a list
of pairs.  Then you surely need to write a class, since access by keys is
inconveneint for just a list pair.  I suggest calling it "PairList".

One of the globals access optimization PEPs uses a similar structure and
calls it "dlict" but there the implication is that every key appears only
once so you might want to avoid the confusion.

-- 
Beni Cherniavsky <cben at tx.technion.ac.il>







More information about the Python-list mailing list