Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. class Trie:
  2. """Бор слов"""
  3. def __init__(self, word = None):
  4. self.trie = {"Root": {}}
  5. if word != None:
  6. Trie.add_word(word)
  7. def __repr__(self):
  8. return("Trie of words")
  9. def __str__(self):
  10. return("I'm going to do it later")
  11. def add_word(self, word):
  12. now = self.trie["Root"]
  13. for i in word:
  14. if(i not in now):
  15. now[i] = {}
  16. now = now[i]
  17. else:
  18. now = now[i]
  19. else:
  20. now["end"] = ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement