Skip to content

Instantly share code, notes, and snippets.

@ShawonAshraf
Created November 16, 2020 21:13
Show Gist options
  • Save ShawonAshraf/e5c336b9d2336546190af95ee4c2c6ac to your computer and use it in GitHub Desktop.
Save ShawonAshraf/e5c336b9d2336546190af95ee4c2c6ac to your computer and use it in GitHub Desktop.
irtm boolean and
paris = [1, 2, 3, 4, 5, 7, 8, 9, 11, 12, 13, 14, 15]
france = [2, 6, 10, 12, 14]
def query(posting1, posting2):
result = []
it1 = iter(posting1)
it2 = iter(posting2)
el1 = next(it1)
el2 = next(it2)
s = max(len(posting1), len(posting2))
for _ in range(s):
try:
if el1 == el2:
result.append(el1)
el1 = next(it1)
el2 = next(it2)
if el1 < el2:
# go forward in 1
el1 = next(it1)
if el1 > el2:
# go forward in 2
el2 = next(it2)
except StopIteration:
break
return result
r = query(paris, france)
print(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment