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

Amit Khemka khemkaamit at
Wed Apr 4 09:08:50 CEST 2007

On 3 Apr 2007 11:20:33 -0700, bahoo <b83503104 at> wrote:
> Hi,
> 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.

To remove all items with multiple occurances in myList:

list(set(myList) - set([x for x in myList if myList.count(x)>1]))

Amit Khemka --
Home Page:
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.

More information about the Python-list mailing list