Pythonic way to compare two lists and print out the differences

前端 未结 7 1725
滥情空心
滥情空心 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条回答
  •  你的背包
    2021-02-07 11:31

    edit: oops, didn't see the "ignore first item" part

    from itertools import islice,izip
    
    for a,b in islice(izip(list1,list2),1,None):
        if a != b:
           print a, b
    

提交回复
热议问题