Python - getting just the difference between strings

后端 未结 6 2141
心在旅途
心在旅途 2021-01-12 08:12

What\'s the best way of getting just the difference from two multiline strings?

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


        
6条回答
  •  孤独总比滥情好
    2021-01-12 08:45

    Building on @Chris_Rands comment, you can use the splitlines() operation too (if your strings are multi-lines and you want the line not present in one but the other):

    b_s = b.splitlines()
    a_s = a.splitlines()
    [x for x in b_s if x not in a_s]
    

    Expected output is:

    [' testing this is working 2']
    

提交回复
热议问题