MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / signature

Function signature

strings/anagrams.py:8–22  ·  view source on GitHub ↗

Return a word's frequency-based signature. >>> signature("test") 'e1s1t2' >>> signature("this is a test") ' 3a1e1h1i2s3t3' >>> signature("finaltest") 'a1e1f1i1l1n1s1t2'

(word: str)

Source from the content-addressed store, hash-verified

6
7
8def signature(word: str) -> str:
9 """
10 Return a word's frequency-based signature.
11
12 >>> signature("test")
13 'e1s1t2'
14 >>> signature("this is a test")
15 ' 3a1e1h1i2s3t3'
16 >>> signature("finaltest")
17 'a1e1f1i1l1n1s1t2'
18 """
19 frequencies = collections.Counter(word)
20 return "".join(
21 f"{char}{frequency}" for char, frequency in sorted(frequencies.items())
22 )
23
24
25def anagram(my_word: str) -> list[str]:

Callers 2

anagramFunction · 0.85
anagrams.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected