获取错误 'tuple' 对象没有属性 'split'

gettinf error 'tuple' object has no attribute 'split'

def generateTopics(corpus, dictionary):
    # Build LDA model using the above corpus
    lda = models.ldamodel.LdaModel(corpus, id2word=dictionary, num_topics=50)
    corpus_lda = lda[corpus]

    # Group topics with similar words together.
    tops = set(lda.show_topics(50))
    top_clusters = []
    for l in tops:
        top = []
    for t in l.split(" + "):
        top.append((t.split("*")[0], t.split("*")[1]))
    top_clusters.append(top)

我试图在此代码中使用 lda.but 获取主题,当我尝试将具有相似词的主题组合在一起时,我收到此错误。 对于 l.split(" + ") 中的 t: AttributeError: 'tuple' 对象没有属性 'split'

您只能拆分字符串。

尝试

str(l).split(" + ")

否则,不要使用元组。