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

irstas at gmail.com irstas at gmail.com
Tue Apr 3 22:47:58 CEST 2007


On Apr 3, 10:13 pm, "bahoo" <b83503... at yahoo.com> 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"?

Beware that converting a list to set and then back to list won't
preserve the order of the items, because the set-type loses the order.




More information about the Python-list mailing list