Skip to content

Commit 32109bd

Browse files
github-actionsgithub-actions
github-actions
authored and
github-actions
committed
fixup! Format Python code with psf/black push
1 parent 9ba5c28 commit 32109bd

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

strings/jaro_winkler.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,30 @@ def get_matched_characters(_str1: str, _str2: str) -> str:
3434
matched.append(l)
3535
_str2 = f"{_str2[0:_str2.index(l)]} {_str2[_str2.index(l) + 1:]}"
3636

37-
return ''.join(matched)
37+
return "".join(matched)
3838

3939
# matching characters
4040
matching_1 = get_matched_characters(str1, str2)
4141
matching_2 = get_matched_characters(str2, str1)
4242
match_count = len(matching_1)
4343

4444
# transposition
45-
transpositions = len(
46-
[(c1, c2) for c1, c2 in zip(matching_1, matching_2) if c1 != c2]
47-
) // 2
45+
transpositions = (
46+
len([(c1, c2) for c1, c2 in zip(matching_1, matching_2) if c1 != c2]) // 2
47+
)
4848

4949
if not match_count:
5050
jaro = 0.0
5151
else:
52-
jaro = 1 / 3 * (
53-
match_count / len(str1)
54-
+ match_count / len(str2)
55-
+ (match_count - transpositions) / match_count)
52+
jaro = (
53+
1
54+
/ 3
55+
* (
56+
match_count / len(str1)
57+
+ match_count / len(str2)
58+
+ (match_count - transpositions) / match_count
59+
)
60+
)
5661

5762
# common prefix up to 4 characters
5863
prefix_len = 0
@@ -65,7 +70,8 @@ def get_matched_characters(_str1: str, _str2: str) -> str:
6570
return jaro + 0.1 * prefix_len * (1 - jaro)
6671

6772

68-
if __name__ == '__main__':
73+
if __name__ == "__main__":
6974
import doctest
75+
7076
doctest.testmod()
7177
print(jaro_winkler("hello", "world"))

0 commit comments

Comments
 (0)