Proposed implementation for an Ordered Dictionary
Steven D'Aprano
steve at pearwood.info
Sat Feb 28 11:27:53 EST 2009
More information about the Python-list mailing list
Sat Feb 28 11:27:53 EST 2009
- Previous message (by thread): Proposed implementation for an Ordered Dictionary
- Next message (by thread): Proposed implementation for an Ordered Dictionary
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Colin J. Williams wrote: > Sometimes, it's useful to be able to > obtain the data in the sorted sequence. > > You might consider adding functionality > like: > > def seqItems(self): > '''To return the items, sorted > by key. ''' > return [self[k] for k in > self.seqKeys()] Amazingly, the Python time-machine provides such functionality! Using just a handful of pre-existing pieces, you can do this: sorted(mydict.items()) sorted(mydict.keys()) [mydict[x] for x in sorted(mydict.keys)] and any other sequence you might need. That's the beauty of a general purpose programming language. You don't need everything to be a built-in *wink* -- Steven
- Previous message (by thread): Proposed implementation for an Ordered Dictionary
- Next message (by thread): Proposed implementation for an Ordered Dictionary
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list