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

Skip to content

Commit 27607a7

Browse files
author
Eric Naeseth
committed
Added method FPTree#prefix_paths, which generates the prefix paths that end with the given item.
1 parent 988339f commit 27607a7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

fp_growth.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ def nodes(self, item):
7575
while node:
7676
yield node
7777
node = node.neighbor
78+
79+
def prefix_paths(self, item):
80+
"""Generates the prefix paths that end with the given item."""
81+
82+
def collect_path(node):
83+
path = []
84+
while node and not node.root:
85+
path.append(node)
86+
node = node.parent
87+
path.reverse()
88+
return path
89+
90+
return (collect_path(node) for node in self.nodes(item) if node.leaf)
7891

7992

8093
class FPNode(object):

0 commit comments

Comments
 (0)