Book: A Common-Sense Guide to Data Structures and Algorithms, Second Edition
Page 320
Function: collectAllWords
Python Version: CPython version 3.10.0
In the statement def collectAllWords(self, node=None, word="", words=[]), words=[] means every time we call collectAllWords we use the same list. This means the list is not empty after the first call.
code:
# A trie is a tree build from hash table. each node is a hash table pointing to the
# address of another hash table. This is commonly used for word auto complete.
class trie:
def __init__(self):
self.root = trieNode()
# search for a word in the trie, return last node found
def search(self, word):
current_node = self.root
# check every character in string to determin if in trie
for chr in word:
if current_node.children.get(chr):
current_node = current_node.children[chr]
# if not in return
else:
return
# return final node
This file has been truncated. show original
explanation of why:
https://web.archive.org/web/20200221224620/http://effbot.org/zone/default-values.htm
Noted, and thank you! I will clarify this issue in the next version of the book.