Change occurrences of str.format to f-strings (#4118)

* f-string update rsa_cipher.py

* f-string update rsa_key_generator.py

* f-string update burrows_wheeler.py

* f-string update non_recursive_segment_tree.py

* f-string update red_black_tree.py

* f-string update deque_doubly.py

* f-string update climbing_stairs.py

* f-string update iterating_through_submasks.py

* f-string update knn_sklearn.py

* f-string update 3n_plus_1.py

* f-string update quadratic_equations_complex_numbers.py

* f-string update nth_fibonacci_using_matrix_exponentiation.py

* f-string update sherman_morrison.py

* f-string update levenshtein_distance.py

* fix lines that were too long
This commit is contained in:
CarsonHam
2021-02-22 23:53:49 -06:00
committed by GitHub
parent f680806894
commit 61f3119467
14 changed files with 38 additions and 39 deletions

View File

@ -71,13 +71,13 @@ def nth_fibonacci_bruteforce(n):
def main():
fmt = (
"{} fibonacci number using matrix exponentiation is {} and using bruteforce "
"is {}\n"
)
for ordinal in "0th 1st 2nd 3rd 10th 100th 1000th".split():
n = int("".join(c for c in ordinal if c in "0123456789")) # 1000th --> 1000
print(fmt.format(ordinal, nth_fibonacci_matrix(n), nth_fibonacci_bruteforce(n)))
print(
f"{ordinal} fibonacci number using matrix exponentiation is "
f"{nth_fibonacci_matrix(n)} and using bruteforce is "
f"{nth_fibonacci_bruteforce(n)}\n"
)
# from timeit import timeit
# print(timeit("nth_fibonacci_matrix(1000000)",
# "from main import nth_fibonacci_matrix", number=5))

View File

@ -175,9 +175,7 @@ class Matrix:
result[r, c] += self[r, i] * another[i, c]
return result
else:
raise TypeError(
"Unsupported type given for another ({})".format(type(another))
)
raise TypeError(f"Unsupported type given for another ({type(another)})")
def transpose(self):
"""
@ -260,7 +258,7 @@ if __name__ == "__main__":
print(f"v is {v}")
print("uv^T is %s" % (u * v.transpose()))
# Sherman Morrison
print("(a + uv^T)^(-1) is {}".format(ainv.ShermanMorrison(u, v)))
print(f"(a + uv^T)^(-1) is {ainv.ShermanMorrison(u, v)}")
def test2():
import doctest