how to remove multiple occurrences of a string within a list?

Steve Holden steve at
Tue Apr 3 22:21:24 CEST 2007

bahoo wrote:
> On Apr 3, 2:31 pm, "Matimus" <mccre... at> wrote:
>> It depends on your application, but a 'set' might really be what you
>> want, as opposed to a list.
>>>>> s = set(["0024","haha","0024"])
>>>>> s
>> set(["0024","haha"])>>> s.remove("0024")
>>>>> s
>> set(["haha"])
> This sounds cool.
> But is there a command I can convert the "set" back to a "list"?
That would be list(). So what you want is

s = set(["0024","haha","0024"])
l = list(s)

or something like it. It seems, a priori, unlikely that you only want to 
remove items with that specific value, Is this part of some larger problem?

Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd
Skype: holdenweb
Recent Ramblings

More information about the Python-list mailing list