比较两个bigrams列表并返回匹配的bigram

时间:2020-04-20 17:32:45

标签: python list nlp nltk list-comprehension

请提出如何比较2个双字母组列表并仅返回匹配的双字母组的建议。 从下面的示例列表中,如何返回匹配的二元组 ['two','thre']

bglist1 = 
[['one', 'two'],
 ['two', 'three'],
 ['three', 'four']]

bglist2 = 
[['one', 'six'],
 ['two', 'four'],
 ['two', 'three']]

1 个答案:

答案 0 :(得分:1)

您可以仅测试双字母组是否在其他双字母组列表中。

out = list()

for x in bglist1:
    if x in bglist2:
        out.append(x)

这将为您提供两个bglist中的列表列表。