Question

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?

Was it helpful?

Solution

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

OTHER TIPS

you can sort a dict.items() list (of tuples) .. can't?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top