Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## https://medium.com/@shahikhashayar/and-or-and-not-boolean-queries-on-inverted-indexes-in-python-8030bb5d9098
- def OR(posting1, posting2):
- p1 = 0
- p2 = 0
- result = list()
- while p1 < len(posting1) and p2 < len(posting2):
- if posting1[p1] == posting2[p2]:
- result.append(posting1[p1])
- p1 += 1
- p2 += 1
- elif posting1[p1] > posting2[p2]:
- result.append(posting2[p2])
- p2 += 1
- else:
- result.append(posting1[p1])
- p1 += 1
- while p1 < len(posting1):
- result.append(posting1[p1])
- p1 += 1
- while p2 < len(posting2):
- result.append(posting2[p2])
- p2 += 1
- return result
- l1 = [1,7,8]
- l2 = [1,5,12]
- #print(OR(l1,l2))
- print(l1,l2)
- ## CONJUNTOS
- ## OR
- print(list( set(l1) | set(l2) ) ) # operador | = UNIAO
- ## AND
- print(list( set(l1) & set(l2) ) ) # operador & = INTERSECAO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement