在使用以下 def 查找语料库中最常用的 10 个单词(使用 Python)后,我必须比较这 10 个单词在所述语料库的不同子类别中的上下文。
def meest_freq(mycorpus):
    import string
    woorden = mycorpus.words()
    zonderhoofdletters = [word.lower() for word in woorden]
    filtered = [word for word in zonderhoofdletters if word not in stopList]
    no_punct = [s.translate(None, string.punctuation) for s in filtered]
    word_counter = {}
    D = defaultdict(int)
    for word in no_punct:
        D[word] +=1
    popular_words = sorted(D, key = D.get, reverse = True)
    woord1 = popular_words[1]
    woord2 = popular_words[2]
    woord3 = popular_words[3]
    woord4 = popular_words[4]
    woord5 = popular_words[5]
    woord6 = popular_words[6]
    woord7 = popular_words[7]
    woord8 = popular_words[8]
    woord9 = popular_words[9]
    woord10 = popular_words[10]
    print "De 10 meest frequente woorden zijn: ", woord1, ",", woord2, ',', woord3, ',', woord4, ',', woord5, ',', woord6, ',', woord7, ',', woord8, ',', woord9, "en", woord10
    return popular_words
我想使用以下代码来做到这一点:
def context(cat):
    words = popular_words[:10]
    context = words.concordance()
    print context
不幸的是,我不断收到“AttributeError:'str'对象没有属性'concordance'有谁知道为什么我不能在第二个def中使用我的第一个代码块的结果?我认为应该使用return-statement能工作。