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

Steve Holden steve at holdenweb.com
Tue Apr 3 16:21:24 EDT 2007


bahoo wrote:
> On Apr 3, 2:31 pm, "Matimus" <mccre... at gmail.com> 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"])
s.remove("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?

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Recent Ramblings       http://holdenweb.blogspot.com




More information about the Python-list mailing list