I know this is an old question, but here's my unique solution: class inheritance!:
class UniqueList(list):
def appendunique(self,item):
if item not in self:
self.append(item)
return True
return False
Then, if you want to uniquely append items to a list you just call appendunique on a UniqueList. Because it inherits from a list, it basically acts like a list, so you can use functions like index() etc. And because it returns true or false, you can find out if appending succeeded (unique item) or failed (already in the list).
To get a unique list of items from a list, use a for loop appending items to a UniqueList (then copy over to the list).
Example usage code:
unique = UniqueList()
for each in [1,2,2,3,3,4]:
if unique.appendunique(each):
print 'Uniquely appended ' + str(each)
else:
print 'Already contains ' + str(each)
Prints:
Uniquely appended 1
Uniquely appended 2
Already contains 2
Uniquely appended 3
Already contains 3
Uniquely appended 4
Copying to list:
unique = UniqueList()
for each in [1,2,2,3,3,4]:
unique.appendunique(each)
newlist = unique[:]
print newlist
Prints:
[1, 2, 3, 4]