您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python-获得字符串之间的区别

Python-获得字符串之间的区别

a = 'testing this is working \n testing this is working 1 \n'
b = 'testing this is working \n testing this is working 1 \n testing this is working 2'

splitA = set(a.split("\n"))
splitB = set(b.split("\n"))

diff = splitB.difference(splitA)
diff = ", ".join(diff)  # ' testing this is working 2, more things if there were...'

从本质上讲,使每个字符串由一组行组成,并采用集合差-即B中所有不在A中的东西。然后取该结果并将其全部连接到一个字符串中。

编辑:这是说@ShreyasG说的一种糊涂方式-[如果x不在y中,则x用于x] …

python 2022/1/1 18:35:35 有208人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶