Created
November 23, 2015 15:52
-
-
Save mvallebr/7a6e5e6dd3384ae261f6 to your computer and use it in GitHub Desktop.
This file contains 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 only_in_x_generator(x, y): | |
ix = 0 | |
iy = 0 | |
while ix < len(x) and iy < len(y): | |
if x[ix] < y[iy]: | |
yield x[ix] | |
ix += 1 | |
elif x[ix] > y[iy]: | |
iy += 1 | |
else: | |
ix += 1 | |
iy += 1 | |
x = [1, 3, 5, 6, 7, 8, 15, 20] | |
y = [1, 2, 4, 7, 8, 15, 21] | |
print str([k for k in only_in_x_generator(x, y)]) | |
############################################################# | |
# $ python only_in_x_generator.py | |
# [3, 5, 6, 20] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment