Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/dsa/various.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from collections import Counter


class Graph:
Expand Down Expand Up @@ -78,14 +79,8 @@ def is_palindrome(text: str) -> bool:


def word_frequency(text: str) -> dict[str, int]:
words = text.lower().split()
frequency = {}
for word in words:
if word in frequency:
frequency[word] += 1
else:
frequency[word] = 1
return frequency
# Use Counter for faster word counting
return dict(Counter(text.lower().split()))


class PathFinder:
Expand Down