how to remove multiple occurrences of a string within a list?
khemkaamit at gmail.com
Wed Apr 4 09:08:50 CEST 2007
On 3 Apr 2007 11:20:33 -0700, bahoo <b83503104 at yahoo.com> wrote:
> I have a list like ['0024', 'haha', '0024']
> and as output I want ['haha']
> If I
> 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 -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
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