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] …