From c3fabb282d429de931ef10c91cee55700578eb86 Mon Sep 17 00:00:00 2001 From: Mitar Date: Mon, 15 Oct 2012 04:16:46 -0700 Subject: [PATCH] Allow reversed iteration over SortedDict. Iterators cannot be reversed easily without this method. --- django/utils/datastructures.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index ad17573104..d94a05dfb4 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -160,6 +160,9 @@ class SortedDict(dict): def __iter__(self): return iter(self.keyOrder) + def __reversed__(self): + return reversed(self.keyOrder) + def pop(self, k, *args): result = super(SortedDict, self).pop(k, *args) try: