我有两个长度相等的字符串,希望匹配索引相同的单词。我也在尝试连续比赛,这是我遇到麻烦的地方。在
例如,我有两条弦
alligned1 = 'I am going to go to some show'
alligned2 = 'I am not going to go the show'
我想要的是得到结果:
^{pr2}$我目前的代码如下:
keys = []
for x in alligned1.split():
for i in alligned2.split():
if x == i:
keys.append(x)
这给了我:
['I','am','show']
任何指导或帮助将不胜感激。在
代码简化如下:
然后我们需要跟踪是否匹配了一个单词,让我们用一个标志变量来完成。在
^{pr2}$嗯Kevin's answer是最好的,也是最合适的。我试着用暴力的方式来做。它看起来不太好,但却很管用,没有任何进口产品
输出
^{pr2}$找到匹配的单词是相当简单的,但是将它们放在相邻的组中是相当困难的。我建议使用
groupby
。在结果:
^{pr2}$相关问题 更多 >
编程相关推荐