Pythonic way to compare two lists and print out the differences
list1=[1,2,3,4]
list2=[1,5,3,4]
print [(i,j) for i,j in zip(list1,list2) if i!=j]
Output:
[(2, 5)]
Edit: Easily extended to skip n first items (same output):
list1=[1,2,3,4]
list2=[2,5,3,4]
print [(i,j) for i,j in zip(list1,list2)[1:] if i!=j]
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