Skip to content

Commit 40e69c2

Browse files
Merge pull request #3 from Atakey/patch-1
Update __init__.py
2 parents d7dabff + a8b5ce1 commit 40e69c2

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

ahocorasick/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding:utf-8
22
# write by zhou
3-
3+
from collections import defaultdict
44

55
class Node(object):
66
"""
@@ -40,7 +40,7 @@ def __init__(self, *words):
4040
self.words = list(self.words_set)
4141
self.words.sort(key=lambda x: len(x))
4242
self._root = Node(is_root=True)
43-
self._node_meta = {}
43+
self._node_meta = defaultdict(set)
4444
self._node_all = [(0, self._root)]
4545
_a = {}
4646
for word in self.words:
@@ -58,7 +58,6 @@ def node_append(keyword):
5858
else:
5959
_[k] = node
6060
self._node_all.append((_i+1, _[k]))
61-
self._node_meta.setdefault(id(_[k]),set())
6261
if _i >= 1:
6362
for _j in _a[k]:
6463
if keyword[:_i+1].endswith(_j):

0 commit comments

Comments
 (0)