[Tutor] setting lists
nswitanek at stanford.edu
Wed Jan 10 07:13:06 CET 2007
I'd like to remove redundant items from a list, and have read that using
set() is an effective way to do it. But I often get the following error,
and I'd be glad for your help understanding what's wrong.
>>> z = ['test','test',1,2,1]
set(['test', 1, 2])
>>> list(set(z)) # Works as I expect
['test', 1, 2]
>>> type(n) # This is a list of lists of strings
>>> n1 = list(set(n))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: list objects are unhashable
More information about the Tutor