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

2024-10-02 18:17:00 发布

您现在位置:Python中文网/ 问答频道 /正文

请建议如何比较2个bigram列表并仅返回匹配的bigram。 从下面的示例列表中,如何返回匹配的bigram['two','three']

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

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

Tags: 示例列表one建议threefourtwosix
1条回答
网友
1楼 · 发布于 2024-10-02 18:17:00

您可以只测试这个二元图是否在另一个二元图列表中

out = list()

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

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

相关问题 更多 >