parsed.org
Remove Duplicates by xinu on Jan 13, 2005 08:50 AM

Remove duplicate elements from a list:

newList = dict([(item, 1) for item in oldList]).keys()

Or, if you have Python 2.3 or newer, you can use a Set object to collapse your list:

import sets
newList = list(sets.Set(oldList))
dataimportlanguagesprogrammingpythonsetsyntax
RSS