I'm new to Python, and using Google App Engine, which is currently running only Python 2.5. Are there any built-in ways of doing an ordered dictionary, or do I have to implement something custom?
A:
OrderedDict is new in 2.7, so no, there's no built-in way to do this - you'll have to implement your own.
Usually, an ordered dictionary is implemented as a dictionary of linked list nodes, linked in traversal order. This should be fairly straightforward to implement yourself.
Nick Johnson
2010-10-12 08:20:58
+1
A:
Django provides a SortedDict class, which has the same functionality. If you are using django, you can just use from django.utils.datastructures import SortedDict
.
Even if you're not using django, you can still take advantage of that implementation. Just get the datastructures.py file from the django source and save it somewhere importable.
http://code.djangoproject.com/browser/django/trunk/django/utils/datastructures.py
AndrewF
2010-10-12 11:22:47