circular_linked_list: Add more len() tests (#2051)

* circular_linked_list: Add more len() tests

* fixup! Format Python code with psf/black push

* prepend()

* updating DIRECTORY.md

* Fix decrementation of self.length

* Add empty list tests

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Christian Clauss
2020-05-31 09:36:57 +02:00
committed by GitHub
parent 3357768fc3
commit 1e8fe8efcf
3 changed files with 37 additions and 11 deletions

View File

@ -34,7 +34,7 @@ def jaro_winkler(str1: str, str2: str) -> float:
matched.append(l)
_str2 = f"{_str2[0:_str2.index(l)]} {_str2[_str2.index(l) + 1:]}"
return ''.join(matched)
return "".join(matched)
# matching characters
matching_1 = get_matched_characters(str1, str2)
@ -42,17 +42,22 @@ def jaro_winkler(str1: str, str2: str) -> float:
match_count = len(matching_1)
# transposition
transpositions = len(
[(c1, c2) for c1, c2 in zip(matching_1, matching_2) if c1 != c2]
) // 2
transpositions = (
len([(c1, c2) for c1, c2 in zip(matching_1, matching_2) if c1 != c2]) // 2
)
if not match_count:
jaro = 0.0
else:
jaro = 1 / 3 * (
match_count / len(str1)
+ match_count / len(str2)
+ (match_count - transpositions) / match_count)
jaro = (
1
/ 3
* (
match_count / len(str1)
+ match_count / len(str2)
+ (match_count - transpositions) / match_count
)
)
# common prefix up to 4 characters
prefix_len = 0
@ -65,7 +70,8 @@ def jaro_winkler(str1: str, str2: str) -> float:
return jaro + 0.1 * prefix_len * (1 - jaro)
if __name__ == '__main__':
if __name__ == "__main__":
import doctest
doctest.testmod()
print(jaro_winkler("hello", "world"))