[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:
imp 2021-08-19 20:08:20 +08:00 committed by GitHub
parent 9cb5760e89
commit 20a4fdf384
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 4 deletions

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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: