Iterating over a dictionary's sorted keys
petersc at stud.ntnu.no
Mon May 29 10:46:44 CEST 2000
Mark Hammond wrote:
> I agree its handy, but dont think it's worth adding a convenience function
> to collapse two lines down to one. There are _lots_ of really, really
> handy things you can do in 2 lines of Python, so where would we stop?
When we reach the complexity of the Java interface...
But he can always take a copy of UserDict.py with his program an put
his convenience stuff in there. As long as he distributes myDict.py
it's imho no problem.
*** UserDict.py Mon May 29 10:41:25 2000
--- myDict.py Mon May 29 10:39:19 2000
*** 21,26 ****
--- 21,30 ----
def keys(self): return self.data.keys()
+ def sorted_keys(self):
+ keys = self.data.keys()
+ return keys
def items(self): return self.data.items()
def values(self): return self.data.values()
def has_key(self, key): return self.data.has_key(key)
More information about the Python-list