Last active
August 29, 2015 14:11
-
-
Save betatim/221cae4aef0ce8ceddf7 to your computer and use it in GitHub Desktop.
Better name and more pythonic way of doing this?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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