[Tutor] Python creating trie

anish singh anish198519851985 at gmail.com
Sun Nov 12 05:37:06 EST 2017

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

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


More information about the Tutor mailing list