2 from collections
import OrderedDict
5 def __init__(self
, name
):
7 self
.children
= OrderedDict()
11 if name
in self
.children
:
12 self
.children
[name
].count
+= 1
14 self
.children
[name
] = Trie(name
)
15 return self
.children
[name
]
17 def print(self
, depth
):
20 for i
in range(depth
):
24 print(self
.name
, '#', self
.count
)
25 for key
, child
in self
.children
.items():
26 child
.print(depth
+ 1)
31 if __name__
== "__main__":
32 for line
in sys
.stdin
:
33 words
= line
.split('==>')
34 words
= [word
.strip() for word
in words
]
37 MyTrie
= MyTrie
.add(word
)