On 14-Jun-08, at 8:39 PM, Armin Ronacher wrote: > ... > I noticed lately that quite a few projects are implementing their own > subclasses of `dict` that retain the order of the key/value pairs. > ... I'm +1 on this one too, as there are at least a couple of times in recent memory when I would have found this useful. And, as far as questions about the definition of an ordered dictionary, is there any good reason not to simply treat the dict as a list? Something like (with the obvious bits left out): class odict(dict): def __init__(self, *args): self._order = [] def __setitem__(self, key, val): if key not in self: self._order.append(key) def __iter__(self): return self._order def items(self): return ([item, self[item] for item in self._order]) def sort(self): self._order.sort() ... and so on ... That way all the order-related functions are well defined, so it would be hard claim that it doesn't do the "right thing" without claiming that lists don't do the "right thing".
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4