Skip to content
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

[mypy] Fix type annotations for strings #4637

Merged
merged 4 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion strings/can_string_be_rearranged_as_palindrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion strings/levenshtein_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
2 changes: 1 addition & 1 deletion strings/word_occurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion strings/word_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_word_pattern(word: str) -> str:
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:
Expand Down