A sorted map type.

Mark Pilgrim f8dy at diveintopython.org
Fri Apr 13 19:39:06 EDT 2001


in article slrn9dbfe5.qmh.apardon at trout.vub.ac.be, apardon at trout.vub.ac.be
at apardon at trout.vub.ac.be wrote on 4/12/01 10:33 AM:

> Is there a module that provides a sorted map.
> 
> What I need is a map type that allow you to visit
> all members in key order. Also the possibility
> to look for the next in line after a search
> would be nice. Is there a module that already
> implements such a maptype or do I have to do
> it myself?

>From the Python Cookbook:
  "Dictionaries can't be sorted -- a mapping has no ordering! -- so, when
you feel the need to sort one, you no doubt want to sort its *keys* (in a
separate list). Sorting (key,value) pairs (items) is simplest, but not
fastest."
    http://www.activestate.com/ASPN/Python/Cookbook/Recipe/52306

Article and associated code by Alex Martelli, which, if you're new around
here, means it's definitive.

-M
You're smart; why haven't you learned Python yet?
http://diveintopython.org/




More information about the Python-list mailing list