[Tutor] Sort a Set

Hugo González Monteverde hugonz-lists at h-lab.net
Tue Aug 23 21:53:38 CEST 2005


I've done:

undup = []
for i in list:
     if i not in undup:
         undup.append(i)

Which is simple an not very pythonic, but does the trick.

Hugo



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.
> 
> For get the values i use:
> 
> [x[0] for x in cardTmp]
> 
> or:
> 
> from itertools import imap
> for i in imap(lambda x: x[0], cardTmp): print i
> 
> A idea it would be create a generator that will return elements one by 
> one, and then it would be possible know if that element is in the new 
> list. But generators are in 2.4
> 
> 
> Python 2.3.5
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


More information about the Tutor mailing list