Python's simplicity philosophy
Andrew Dalke
adalke at mindspring.com
Wed Nov 19 19:03:30 EST 2003
Paul Rubin:
> Uniq should only have to work on sorted lists.
*shrug* Okay, that's different than the unix 'uniq'
command. I've needed the unix one more than I've
needed yours. And I've used what can now be
written as
unique_keys = dict.from_keys(lst).keys()
much more often. Well, it requires that the objects
be hashable and define == while yours requires
that they define == and < (or define < and use it
twice). Note that your uniq wouldn't work on
complex numbers because those don't define <.
Tack on a 'unique_keys.sort()' and those two lines
give pretty much what you want, except the check
that the original list is sorted.
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list