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

Skip to content

Commit 2c14ab4

Browse files
author
Eric Naeseth
committed
Adding FPTree#nodes(item), which generates all of the nodes that contain the given item.
1 parent e8047a9 commit 2c14ab4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

fp_growth.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ def add(self, transaction):
5353
self._paths[item] = [next_point, next_point]
5454

5555
point = next_point
56+
57+
def nodes(self, item):
58+
"""
59+
Generates the sequence of nodes that contain the given item.
60+
"""
61+
62+
try:
63+
node = self._paths[item][0]
64+
except KeyError:
65+
return
66+
67+
while node:
68+
yield node
69+
node = node.neighbor
5670

5771

5872
class FPNode(object):

0 commit comments

Comments
 (0)