good name for a dict/list hybrid

logistix logistix at zworg.com
Tue Jan 7 01:02:32 EST 2003


Andrew Dalke <adalke at mindspring.com> wrote in message news:<avd4ti$2jr$1 at slb0.atl.mindspring.net>...
> 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.
> 
> Here's what it looks like
> 
>  >>> dl = DictList.DictList()
>  >>> dl["Name"] = "Andrew"
>  >>> dl["PubDate"] = "1975 Jun"
>  >>> dl["Lang"] = "English"
>  >>> print dl.keys()
>  ['Lang', 'Name', 'PubDate']
>  >>> print dl[0]
>  ('Name', 'Andrew')
>  >>> dl["Name"] = "Andrew Dalke"  # Duplicate entry
>  >>> dl["Name"]                   # Only gets the first entry
>  'Andrew'
>  >>> dl.getall("Name")            # Gets all "Name" entries
>  ['Andrew', 'Andrew Dalke']
>  >>> dl.allitems()
>  >>> list(dl.allitems())
> [('Name', 'Andrew'), ('PubDate', '1975 Jun'), ('Lang', 'English'), 
> ('Name', 'Andrew Dalke')]
>  >>> del dl["PubDate"]
>  >>> list(dl.allitems())
>  [('Name', 'Andrew'), ('Lang', 'English'), ('Name', 'Andrew Dalke')]
>  >>> dl.keys()
>  ['Lang', 'Name']
>  >>>
> 
> 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.)
> 
> What should I use?
> 
> Code will be posted after I get a good name.  :)
> 
> 
> 					Andrew
> 					dalke at dalkescientific.com

Something with "bucket"?
DictBuckets, KeyValBuckets?




More information about the Python-list mailing list