Can someone explain me this code to create a trie
from words?

import collections
words = ["bad", "sad", "abyss"]

Trie = lambda: collections.defaultdict(Trie)
trie = Trie()
END = True

for i, word in enumerate(words):
    reduce(dict.__getitem__, word, trie)[END] = i
print(trie.values())


I am not able to understand lambda usage and reduce
function here.

Thanks,
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to