4 Commits

Author SHA1 Message Date
Sowndappan S
37b34c2bac perf(strings): optimize anagram signature using frequency counts (#12927)
* fix(strings): use frequency-based signature for anagrams

Replaced the sorting-based signature implementation with a frequency-based
approach using `collections.Counter`. This ensures that the signature
represents both characters and their counts, preventing collisions and
better grouping of true anagrams.

Examples:
- "test" → "e1s1t2"
- "finaltest" → "a1e1f1i1l1n1s1t2"
- "this is a test" → " 3a1e1h1i2s3t3"

Also updated the anagram lookup to use the new frequency-based signatures, making results more accurate and avoiding false positives.

* Refactor anagram function return type to list[str]

* Update anagrams.py

* Update anagrams.py

* Update anagrams.py

* Update anagrams.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-08-24 15:33:18 +03:00
ok-open-sc
0c5f1c0130 Increased Readability Of Variables (#6400)
* Increased Readability Of Variables

* Update anagrams.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update anagrams.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-30 08:11:17 +01:00
Leoriem-code
4c9949f636 edited strings/anagram.py (#5770)
* rewrote anagrams.py, added doctests

* corrected mistakes

* add anagrams.txt

* Update anagrams.py

* Update strings/anagrams.py

Co-authored-by: Christian Clauss <cclauss@me.com>

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-11-08 18:58:15 +01:00
algobytewise
0ee8f792e3 Moved "other/anagrams.py" to the string folder (#4289)
* move&rename, changed code accordingly

* adjusted codespell ignore-list
2021-03-22 11:40:23 +01:00