mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-20 00:02:04 +00:00
[mypy] Fix type annotations for strings (#4637)
* Fix mypy error for can_string_be_rearranged_as_pal * Fix mypy error for levenshtein_distance.py * Fix mypy error for word_patterns.py * Fix mypy error for word_occurrence.py
This commit is contained in:
parent
9cb5760e89
commit
20a4fdf384
|
@ -43,7 +43,7 @@ def can_string_be_rearranged_as_palindrome(input_str: str = "") -> bool:
|
|||
return True
|
||||
lower_case_input_str = input_str.replace(" ", "").lower()
|
||||
# character_freq_dict: Stores the frequency of every character in the input string
|
||||
character_freq_dict = {}
|
||||
character_freq_dict: dict[str, int] = {}
|
||||
|
||||
for character in lower_case_input_str:
|
||||
character_freq_dict[character] = character_freq_dict.get(character, 0) + 1
|
||||
|
|
|
@ -41,7 +41,7 @@ def levenshtein_distance(first_word: str, second_word: str) -> int:
|
|||
if len(second_word) == 0:
|
||||
return len(first_word)
|
||||
|
||||
previous_row = range(len(second_word) + 1)
|
||||
previous_row = list(range(len(second_word) + 1))
|
||||
|
||||
for i, c1 in enumerate(first_word):
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ def word_occurence(sentence: str) -> dict:
|
|||
>>> dict(word_occurence("Two spaces"))
|
||||
{'Two': 1, 'spaces': 1}
|
||||
"""
|
||||
occurrence = defaultdict(int)
|
||||
occurrence: dict = defaultdict(int)
|
||||
# Creating a dictionary containing count of each word
|
||||
for word in sentence.split():
|
||||
occurrence[word] += 1
|
||||
|
|
|
@ -28,7 +28,7 @@ if __name__ == "__main__":
|
|||
with open("dictionary.txt") as in_file:
|
||||
wordList = in_file.read().splitlines()
|
||||
|
||||
all_patterns = {}
|
||||
all_patterns: dict = {}
|
||||
for word in wordList:
|
||||
pattern = get_word_pattern(word)
|
||||
if pattern in all_patterns:
|
||||
|
|
Loading…
Reference in New Issue
Block a user