I recently came across some Java code that simply put some strings into a Java TreeSet, implemented a distance based comparator for it, and then made its merry way into the
1. I don't think python has a built-in Sorted sets. How about something like this?
letters = ['w', 'Z', 'Q', 'B', 'C', 'A']
for l in sorted(set(letters)):
print l
2.Java TreeSet
is an implementation of the abstraction called SortedSet
. Basic types will be sorted on natural order.A TreeSet
instance performs all key comparisons using its compareTo (or compare) method.So your custom keys should implement proper compareTo