[Tutor] Sort a Set

Kent Johnson kent37 at tds.net
Tue Aug 23 20:06:42 CEST 2005


Terry Carroll wrote:
> Sorry, I missed you were on 2.3.x, and I think sorted() is new with 2.4.  
> You'd instead have to do the sort in a separate step:
> 
> 
>>>>l=[24, 24, 15, 16, 16, 15, 24]
>>>>l=list(set(l))
>>>>l.sort(reverse=True)
>>>>l
> 
> [24, 16, 15]

Actually the reverse parameter is new in 2.4 too, you have to do that in a separate step also:
l=list(set(l))
l.sort()
l.reverse()

Kent



More information about the Tutor mailing list