Skip to content

Commit 789f76d

Browse files
committed
fix: fixing the key structure to a tuple that can be an hashable structure
1 parent 81a9d8d commit 789f76d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

machine_learning/apriori_algorithm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ def prune(itemset: list, candidates: list, length: int) -> list:
4444
>>> prune(itemset, candidates, 3)
4545
[]
4646
"""
47-
itemset_counter = Counter(itemset)
47+
itemset_counter = Counter(tuple(x) for x in itemset)
4848
pruned = []
4949

5050
for candidate in candidates:
5151
is_subsequence = True
5252
for item in candidate:
53-
if item not in itemset_counter or itemset_counter[item] < length - 1:
53+
tupla = tuple(item)
54+
if tupla not in itemset_counter or itemset_counter[tupla] < length - 1:
5455
is_subsequence = False
5556
break
5657
if is_subsequence:

0 commit comments

Comments
 (0)