Python trie implementation