Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 988339f

Browse files
author
Eric Naeseth
committed
Adding a new method: FPNode#remove will remove the given child node.
1 parent a6e1303 commit 988339f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

fp_growth.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ def search(self, item):
109109
except KeyError:
110110
return None
111111

112+
def remove(self, child):
113+
try:
114+
if self._children[child.item] is child:
115+
del self._children[child.item]
116+
else:
117+
raise ValueError("that node is not a child of this node")
118+
except KeyError:
119+
raise ValueError("that node is not a child of this node")
120+
112121
def __contains__(self, item):
113122
return item in self._children
114123

0 commit comments

Comments
 (0)