Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
refactor: remove punctuation signs from popular words, sort popular w…
Browse files Browse the repository at this point in the history
…ords based on frequency
  • Loading branch information
seesmof committed Dec 22, 2023
1 parent dc96f68 commit 77e9f0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/components/PopularWords.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ def updateWords(self):
words.extend(line.split())

popularWords = getPopularWords(words)
sortedPopularWords = sorted(
popularWords.items(), key=lambda x: x[1], reverse=True
)

for word, frequency in popularWords.items():
for word, frequency in sortedPopularWords:
CTkLabel(self.wordsContainer, text=f"{word}: {frequency}").pack(
padx=5, anchor="w"
)
5 changes: 4 additions & 1 deletion src/util/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import date
from math import ceil
from pathlib import Path
from string import punctuation
from rich.console import Console
from customtkinter import *
from collections import Counter
Expand Down Expand Up @@ -34,7 +35,9 @@ def countWords(lines: [str]) -> int:


def getPopularWords(lines: [str]) -> dict:
words = Counter(word for line in lines for word in line.split() if word)
words = Counter(
word.strip(punctuation) for line in lines for word in line.split() if word
)
return dict(words)


Expand Down

0 comments on commit 77e9f0d

Please sign in to comment.