Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. index = { WORD, [url1,url2,url3] }
  2.  
  3. def update_index(word, url):
  4. if word in index and not(url in index[word]):
  5. index[word].append(url) # list already exists append to it
  6. else:
  7. index[word] = [url] # new list with url as a single element
  8.  
  9. def update_index(word, url):
  10. if word in index: # <- isnt having two consecutive if statements
  11. # the same as an AND???
  12. if not(url in index[word]):
  13. index[word].append(url) # list already exists append to it
  14. else:
  15. index[word] = [url] # new list with url as a single element
  16.  
  17. from collections import defaultdict
  18.  
  19. url_store = defaultdict(set)
  20. url_store[word].add(url)
  21.  
  22. if word not in index:
  23. index[word] = [] # create new empty list for word
  24. # now we know that a list exists -> append
  25. if url not in index[word]:
  26. index[word].append(url)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement