[Tutor] Sort a Set
carroll at tjc.com
Tue Aug 23 19:43:40 CEST 2005
On Tue, 23 Aug 2005, Jonas Melian wrote:
> I get a list of repeated numbers [24, 24, 24, 16, 16, 15, 15 ]
> Is possible get it without repeated numbers, without using set()?
> If I use set, then the list is unsorted and i cann't sorting it.
Converting it to a set will eliminate dupes, and converting it back to
list will make it sortable.
I don't know if you're in a position to rely on the sortedness of the
input data, but even if not, this works:
>>> l=[24, 24, 15, 16, 16, 15, 24]
>>> l=sorted(list(set(l)), reverse=True)
[24, 16, 15]
More information about the Tutor