Is there a unique method in python to unique a list?

Token Type typetoken at gmail.com
Sun Sep 9 09:44:53 EDT 2012


Thanks. I try to use set() suggested by you. However, not successful. Please see:
>>> synsets = list(wn.all_synsets('n'))
>>> synsets[:5]
[Synset('entity.n.01'), Synset('physical_entity.n.01'), Synset('abstraction.n.06'), Synset('thing.n.12'), Synset('object.n.01')]
>>> lemma_set = set()
>>> for synset in synsets:
		lemma_set.add(synset.lemma_names)
	

Traceback (most recent call last):
  File "<pyshell#43>", line 2, in <module>
    lemma_set.add(synset.lemma_names)
TypeError: unhashable type: 'list'
>>> for synset in synsets:
		lemma_set.add(set(synset.lemma_names))

Traceback (most recent call last):
  File "<pyshell#45>", line 2, in <module>
    lemma_set.add(set(synset.lemma_names))
TypeError: unhashable type: 'set'





More information about the Python-list mailing list