how to remove duplicated elements in a list?

Bengt Richter bokr at oz.net
Mon Dec 19 07:33:06 EST 2005


On 19 Dec 2005 00:27:48 -0800, bonono at gmail.com wrote:

>
>Steve Holden wrote:
>> Kevin Yuan wrote:
>> > How to remove duplicated elements in a list? eg.
>> > [1,2,3,1,2,3,1,2,1,2,1,3] -> [1,2,3]?
>> > Thanks!!
>> >
>>
>>   >>> list(set([1,2,3,1,2,3,1,2,1,2,1,3]))
>> [1, 2, 3]
>>
>Would this have the chance of changing the order ? Don't know if he
>wants to maintain the order or don't care though.
>
 >>> list(set([1,2,3,1,2,3,1,2,1,2,1,3]))
 [1, 2, 3]
 >>> list(set([1,2,3,1,2,3,'x',1,2,1,2,1,3]))
 [1, 2, 3, 'x']
 >>> list(set([1,'y',2,3,1,2,3,'x',1,2,1,2,1,3]))
 ['y', 1, 2, 3, 'x']

I'd say it does have the chance of changing the order ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list