I was using python defaultdict and I noticed this:
from collections import defautdict
class TrieNode(object):
def __init__(self):
self.children = defaultdict(TrieNode)
self.is_word = False
temp = TrieNode()
if I do:
temp = temp.children['A']
temp
will be a new TrieNode
instance
but if I do:
temp = temp.children.get('B')
temp
can be None.
Why would d.get(key)
vs d[key]
behave differently in defaultdict??