0
for synset in wn.synsets(wordstr):
    len_lemma_names = len (synset.lemma_names)
    #print len_lemma_names, synset.lemma_names
    count_lemma = count_lemma + len_lemma_names
for synset_scores in swn_senti_synset:
    count_synset = count_synset + 1
    #print count_synset, synset_scores

我试图在 count_synset 前面打印 len_lemma_names 但它不起作用。有没有办法将它们打印在一起?谢谢...

4

1 回答 1

1

我认为您想一起迭代这两者。如果是这种情况,您想使用zip,或避免一次将其全部变成一个大列表,itertools.izip

from itertools import izip

for synset, synset_scores in izip(wn.synsets(wordstr), swn_senti_synset):
    # Now you can deal with both at once in this loop.
    len_lemma_names = len(synset.lemma_names)
    count_lemma += len_lemma_names
    count_synset += 1
    # Mix to taste.
    print len_lemma_names, count_synset

请注意,该count_synset部分可能会更好地完成enumerate(我不知道它的初始值或者您是否想在此代码之外使用它)。

于 2012-04-19T13:49:03.077 回答