mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 17:34:49 +08:00
[mypy] annotate compression
(#5570)
This commit is contained in:
@ -12,6 +12,13 @@ of text compression algorithms, costing only some extra computation.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TypedDict
|
||||
|
||||
|
||||
class BWTTransformDict(TypedDict):
|
||||
bwt_string: str
|
||||
idx_original_string: int
|
||||
|
||||
|
||||
def all_rotations(s: str) -> list[str]:
|
||||
"""
|
||||
@ -43,7 +50,7 @@ def all_rotations(s: str) -> list[str]:
|
||||
return [s[i:] + s[:i] for i in range(len(s))]
|
||||
|
||||
|
||||
def bwt_transform(s: str) -> dict:
|
||||
def bwt_transform(s: str) -> BWTTransformDict:
|
||||
"""
|
||||
:param s: The string that will be used at bwt algorithm
|
||||
:return: the string composed of the last char of each row of the ordered
|
||||
@ -75,10 +82,11 @@ def bwt_transform(s: str) -> dict:
|
||||
rotations = all_rotations(s)
|
||||
rotations.sort() # sort the list of rotations in alphabetically order
|
||||
# make a string composed of the last char of each rotation
|
||||
return {
|
||||
response: BWTTransformDict = {
|
||||
"bwt_string": "".join([word[-1] for word in rotations]),
|
||||
"idx_original_string": rotations.index(s),
|
||||
}
|
||||
return response
|
||||
|
||||
|
||||
def reverse_bwt(bwt_string: str, idx_original_string: int) -> str:
|
||||
|
Reference in New Issue
Block a user