Skip to content

Instantly share code, notes, and snippets.

@mvallebr
Created November 23, 2015 15:52
Show Gist options
  • Save mvallebr/7a6e5e6dd3384ae261f6 to your computer and use it in GitHub Desktop.
Save mvallebr/7a6e5e6dd3384ae261f6 to your computer and use it in GitHub Desktop.
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