Pythonic way to compare two lists and print out the differences

前端 未结 7 1742
滥情空心
滥情空心 2021-02-07 10:52

I have two lists which are guaranteed to be the same length. I want to compare the corresponding values in the list (except the first item) and print out the ones which dont mat

7条回答
  •  旧时难觅i
    2021-02-07 11:20

    Nobody's mentioned filter:

    a = [1, 2, 3]
    b = [42, 3, 4]
    
    aToCompare = a[1:]
    bToCompare = b[1:]
    
    c = filter( lambda x: (not(x in aToCompare)), bToCompare)
    print c
    

提交回复
热议问题