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

Paul Rubin http
Wed Apr 4 22:48:14 EDT 2007


"bahoo" <b83503104 at yahoo.com> writes:
> I have a list like ['0024', 'haha', '0024']
> and as output I want ['haha']
> 
> If I
> myList.remove('0024')
> 
> then only the first instance of '0024' is removed.

[x for x in myList if x != '0024']



More information about the Python-list mailing list