文本对齐:使用python提取匹配序列

  发布于 2023-01-20 11:03

我的目标是在两个文本段落中提取对齐的匹配序列.接下来是我的文字:

txt1='the heavy lorry crashed into the building at midnight'
txt2='what a heavy lorry it is that crashed into the building'

预期产量:

'heavy lorry'
'crashed into the building'

我的尝试:

def sequ(s1,s2):
    _split1=s1.split()
    _split2=s2.split()
    _match=''.join(list(set(_split1) & set(_split2)))
    return _match

print sequ(txt1, txt2)

Result: heavybuildingintocrashedthelorry

......扭曲的结果.

有关如何达到预期结果的任何建议?谢谢.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有