Skip to content

Instantly share code, notes, and snippets.

@betatim
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save betatim/221cae4aef0ce8ceddf7 to your computer and use it in GitHub Desktop.

Select an option

Save betatim/221cae4aef0ce8ceddf7 to your computer and use it in GitHub Desktop.
Better name and more pythonic way of doing this?
def lockstep(a, b):
i = j = 0
while i<len(a) and j<len(b):
if a[i] == b[j]:
#yield a[i], b[j]
yield i,j
i+=1;j+=1
elif a[i] < b[j]:
i+=1
elif a[i] > b[j]:
j+=1
a = [1,2,3,4, 6,7,8]
b = [1,2, 4,5,6, 8]
print 'should find', list(sorted(set(a).intersection(set(b))))
for A,B in lockstep(a,b):
print a[A],b[B]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment