Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 10916

A tree-like data structure used to hold an associative array, also called a Prefix Tree.

3 votes

Readability and Performance of my Trie implementation

A note on terminology: a mapping is, according to Python glossary, A container object that supports arbitrary key lookups and implements the methods specified in the Mapping or MutableMapping ab …
Janne Karila's user avatar
  • 10.4k
7 votes
Accepted

Wikipedia Trie pseudocode in Python

You can fix this and simplify the code at the same time: @staticmethod def find(trie, word): for char in word: if char in trie.child: trie = trie.child[char] else: … also take advantage of collections.defaultdict and greatly simplify insert: def __init__(self): self.child = collections.defaultdict(Trie) def insert(self, s, value = 0): node = self for …
Janne Karila's user avatar
  • 10.4k
4 votes

Auto-complete using Tries in Python with OOP

(There should be no duplicate words in the list anyway, because the trie does not store duplicates) def words_with_prefix(self, prefix): results = [] if self.word_end: results.append(prefix …
Janne Karila's user avatar
  • 10.4k