例如:
a = ['The', 'man', 'is', 'eating', 'pear']
eating
和pear
是连续的b = ['these', 'are', 'random', 'words', 'but', 'they', 'have', 'pear', 'and', 'eating']
这是一个随机的单词列表,我想检查b中是否有两个连续的单词
我要怎么做
c = ['eating', 'pear']
最佳答案
c = [(x,y) for x, y in zip(a[0:], a[1:]) if x in b and y in b]
print(c)