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

Chris Angelico rosuav at gmail.com
Sun Sep 9 10:13:17 EDT 2012


On Sun, Sep 9, 2012 at 11:44 PM, Token Type <typetoken at gmail.com> wrote:
>               lemma_set.add(synset.lemma_names)

That tries to add the whole list as a single object, which doesn't
work because lists can't go into sets. There are two solutions,
depending on what you want to do.

1) If you want each addition to remain discrete, make a tuple instead:
lemma_set.add(tuple(synset.lemma_names))

2) If you want to add the elements of that list individually into the
set, use update:
lemma_set.update(synset.lemma_names)

I'm thinking you probably want option 2 here.

ChrisA



More information about the Python-list mailing list