Swati Jaiswal added the comment:
But the work around suggested here as:
def __reversed__(self):
return (self[k] for k in reversed(range(len(self))))
is also not a general solution, i.e. it is applicable for the following case:
m = MyDict({2:40, 0:10, 1:20})
but for any other mapping which does not have 0 as a key, it results in
KeyError. So another solution, which would be more general could be:
def __reversed__(self):
keys = [k for k in self.keys()]
return (self[k] for k in reversed(keys))
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue25864>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com