get rid of duplicate elements in list without set

grocery_stocker cdalten at gmail.com
Sat Mar 21 01:08:10 CET 2009


On Mar 20, 8:34 am, Paul McGuire <pt... at austin.rr.com> wrote:
> On Mar 20, 9:54 am, "thomasvang... at gmail.com"
>
> <thomasvang... at gmail.com> wrote:
> > You could use:
> > B=list(set(A)).sort()
> > Hope that helps.
> > T
>
> That may hurt more than help, sort() only works in-place, and does
> *not* return the sorted list.  For that you want the global built-in
> sorted:

Okay,if sort() only works in-place, then how come the following seems
to return a sorted list

>>> f = [9,7,6,8]
>>> g=f
>>> g
[9, 7, 6, 8]
>>> g.sort()
>>> g
[6, 7, 8, 9]
>>> f
[6, 7, 8, 9]
>>>

Ie, when I sort g, f also seems to get sorted.



More information about the Python-list mailing list