fork download
  1. def doit(list1, list2):
  2. lastmatch = -1
  3. lastunmatch = -1
  4. for i, x in enumerate(zip(list1, list2)):
  5. if x[0] == x[1]:
  6. lastmatch = i
  7. else:
  8. lastunmatch = i
  9. print abs(lastmatch - lastunmatch)
  10.  
  11. list1 = ['cat', 'sat', 'on', 'mat', 'xx', 'yy']
  12. list2 = ['cow', 'sat', 'on', 'carpet', 'xx', 'yy']
  13.  
  14. doit(list1, list2)
  15.  
  16.  
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
1
1
2
1
1
2