Skip to content

Commit c7ca5f3

Browse files
committed
fix(grouping): prevent duplication
1 parent 6003d69 commit c7ca5f3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/rotate_group_words/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,22 @@ def iterating_through_input(words: list[str]) -> Any:
5353
#TODO remove duplicates
5454
"""
5555
result_dic = {}
56+
visited = set()
5657
for w in words:
5758
# instead of adding every possible words, only add those who do not have
5859
# a key in dictionary
5960
# finding an element inside the list of values of a key
6061
# for k in result_dic.keys():
6162
# if result_dic[k] == w:
6263
# break
64+
if w in visited:
65+
continue
6366
result_dic[w] = []
67+
visited.add(w)
6468
for other_word in words:
6569
if is_similar(w, other_word):
6670
result_dic[w].append(other_word)
71+
visited.add(other_word)
6772
# words.remove(other_word)
6873
return result_dic
6974

0 commit comments

Comments
 (0)