In python implementation of trie
with defaultdict
, it is suspicious how this works?
from collections import defaultdict
def trie():
return defaultdict(trie)
Creating Trie:
node = trie()
node
# defaultdict(<function __main__.trie()>, {})
node[0]
# defaultdict(<function __main__.trie()>, {})
node == node[0]
# False
node
# defaultdict(<function __main__.trie()>,
# {0: defaultdict(<function __main__.trie()>, {})})
Can anyone explain how did key=0
got added into trie node
?