Re: [Tutor] Python creating trie

2017-11-12 Thread Steven D'Aprano
On Sun, Nov 12, 2017 at 02:37:06AM -0800, anish singh wrote: > Can someone explain me this code to create a trie > from words? Not really. What makes this a trie? Where did you get this code from? > import collections > words = ["bad", "sad", "abyss"] > > Trie = lambda: collections.defaultdict(

Re: [Tutor] Python creating trie

2017-11-12 Thread Peter Otten
anish singh wrote: > 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, t

[Tutor] Python creating trie

2017-11-12 Thread anish singh
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 no