比较两个二元组列表和 return 匹配的二元组
Compare two bigrams lists and return the matching bigram
请建议如何比较 2 个二元组列表和 return 仅匹配的二元组。
从下面的示例列表中,如何 return 匹配的二元组 ['two'、'three'].
bglist1 =
[['one', 'two'],
['two', 'three'],
['three', 'four']]
bglist2 =
[['one', 'six'],
['two', 'four'],
['two', 'three']]
您可以只测试该双字母组是否在另一个双字母组列表中。
out = list()
for x in bglist1:
if x in bglist2:
out.append(x)
这将为您提供两个 bglist 中的列表列表。
请建议如何比较 2 个二元组列表和 return 仅匹配的二元组。 从下面的示例列表中,如何 return 匹配的二元组 ['two'、'three'].
bglist1 =
[['one', 'two'],
['two', 'three'],
['three', 'four']]
bglist2 =
[['one', 'six'],
['two', 'four'],
['two', 'three']]
您可以只测试该双字母组是否在另一个双字母组列表中。
out = list()
for x in bglist1:
if x in bglist2:
out.append(x)
这将为您提供两个 bglist 中的列表列表。