Ordered dictionary?
Jonathan Daugherty
cygnus at cprogrammer.org
Thu Jan 22 15:36:01 EST 2004
# I need to associate a string (key) with an integer (value). A dictionary
# would do the job, except for the fact that it must be ordered. I also
# need to look up the value for a specific key easily, so a list of tuples
# wouldn't work.
As the other posts on this thread suggest, dictionaries -- by virtue
of their structure -- have no inherently meaningful ordering. You'll
have to either sort the keys (the easy way) or design a wrapper for
the dictionary that maintains a sorted list of the dictionary's
keys and updates it as necessary (the hard way).
--
Jonathan Daugherty
http://www.cprogrammer.org
"It's a book about a Spanish guy called Manual, you should read it."
-- Dilbert
More information about the Python-list
mailing list