Skip to content

added type hints to strings/min_cost_string_conversion.py #2337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions strings/min_cost_string_conversion.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List, Tuple

"""
Algorithm for calculating the most cost-efficient sequence for converting one string
into another.
Expand All @@ -9,7 +11,9 @@
"""


def compute_transform_tables(X, Y, cC, cR, cD, cI):
def compute_transform_tables(
X: str, Y: str, cC: int, cR: int, cD: int, cI: int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is just me but I hate these variable names. Uppercase characters are reserved for constants in Python and single letter and double letter variable names are so old school. They look kludgy in modern programming. Why make the caller/reader guess all the time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, agree with you. I've corrected that in the new commit.

) -> Tuple[List[int], List[str]]:
X = list(X)
Y = list(Y)
m = len(X)
Expand Down Expand Up @@ -46,7 +50,7 @@ def compute_transform_tables(X, Y, cC, cR, cD, cI):
return costs, ops


def assemble_transformation(ops, i, j):
def assemble_transformation(ops: List[str], i: int, j: int) -> List[str]:
if i == 0 and j == 0:
seq = []
return seq
Expand Down