T
Token Type
Is there a unique method in python to unique a list? thanks
Is there a unique method in python to unique a list? thanks
However, if I don't put list(set(lemma_list)) to a variable name, it works
much faster.
Try backdenting that statement. You're currently doing it at every
iteration of the loop - that's why it's so much slower.
1
But you'll probably find it better to work with the set directly,
instead of uniquifying a list as a separate operation.
Try backdenting that statement. You're currently doing it at every
iteration of the loop - that's why it's so much slower.
1
But you'll probably find it better to work with the set directly,
instead of uniquifying a list as a separate operation.
If you don't need to retain order you can just use a set,
Token Type said:synset_list = list(wn.all_synsets(pos))
sense_number = 0
lemma_list = []
for synset in synset_list:
lemma_list.extend(synset.lemma_names)
for lemma in list(set(lemma_list)):
sense_number_new = len(wn.synsets(lemma, pos))
sense_number = sense_number + sense_number_new
return sense_number/len(set(lemma_list))
Paul Rubin said:I think you mean (untested):
synsets = wn.all_synsets(pos)
sense_number = 0
lemma_set = set()
for synset in synsets:
lemma_set.add(synset.lemma_names)
for lemma in lemma_set:
sense_number += len(wn.synsets(lemma,pos))
return sense_number / len(lemma_set)
lemma_set.add(synset.lemma_names)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)
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.