Skip to content

Commit 28419cf

Browse files
cclausspoyea
authored andcommitted
pyupgrade --py37-plus **/*.py (TheAlgorithms#1654)
* pyupgrade --py37-plus **/*.py * fixup! Format Python code with psf/black push
1 parent 34c808b commit 28419cf

File tree

77 files changed

+71
-128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+71
-128
lines changed

backtracking/all_combinations.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
"""
42
In this problem, we want to determine all possible combinations of k
53
numbers out of 1 ... n. We use backtracking to solve this problem.

ciphers/brute_force_caesar_cipher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def decrypt(message):
4040
translated = translated + LETTERS[num]
4141
else:
4242
translated = translated + symbol
43-
print("Decryption using Key #%s: %s" % (key, translated))
43+
print(f"Decryption using Key #{key}: {translated}")
4444

4545

4646
def main():

ciphers/hill_cipher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def checkDeterminant(self):
7878
req_l = len(self.key_string)
7979
if gcd(det, len(self.key_string)) != 1:
8080
raise ValueError(
81-
"discriminant modular {0} of encryption key({1}) is not co prime w.r.t {2}.\nTry another key.".format(
81+
"discriminant modular {} of encryption key({}) is not co prime w.r.t {}.\nTry another key.".format(
8282
req_l, det, req_l
8383
)
8484
)

ciphers/rsa_cipher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def encryptAndWriteToFile(
101101
for i in range(len(encryptedBlocks)):
102102
encryptedBlocks[i] = str(encryptedBlocks[i])
103103
encryptedContent = ",".join(encryptedBlocks)
104-
encryptedContent = "%s_%s_%s" % (len(message), blockSize, encryptedContent)
104+
encryptedContent = "{}_{}_{}".format(len(message), blockSize, encryptedContent)
105105
with open(messageFilename, "w") as fo:
106106
fo.write(encryptedContent)
107107
return encryptedContent

ciphers/rsa_key_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def makeKeyFiles(name, keySize):
4343
publicKey, privateKey = generateKey(keySize)
4444
print("\nWriting public key to file %s_pubkey.txt..." % name)
4545
with open("%s_pubkey.txt" % name, "w") as fo:
46-
fo.write("%s,%s,%s" % (keySize, publicKey[0], publicKey[1]))
46+
fo.write("{},{},{}".format(keySize, publicKey[0], publicKey[1]))
4747

4848
print("Writing private key to file %s_privkey.txt..." % name)
4949
with open("%s_privkey.txt" % name, "w") as fo:
50-
fo.write("%s,%s,%s" % (keySize, privateKey[0], privateKey[1]))
50+
fo.write("{},{},{}".format(keySize, privateKey[0], privateKey[1]))
5151

5252

5353
if __name__ == "__main__":

ciphers/shuffled_shift_cipher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import string
33

44

5-
class ShuffledShiftCipher(object):
5+
class ShuffledShiftCipher:
66
"""
77
This algorithm uses the Caesar Cipher algorithm but removes the option to
88
use brute force to decrypt the message.

ciphers/simple_substitution_cipher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def main():
1717
mode = "decrypt"
1818
translated = decryptMessage(key, message)
1919

20-
print("\n%sion: \n%s" % (mode.title(), translated))
20+
print("\n{}ion: \n{}".format(mode.title(), translated))
2121

2222

2323
def checkValidKey(key):

ciphers/xor_cipher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"""
1919

2020

21-
class XORCipher(object):
21+
class XORCipher:
2222
def __init__(self, key=0):
2323
"""
2424
simple constructor that receives a key or uses

compression/burrows_wheeler.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,14 @@ def reverse_bwt(bwt_string: str, idx_original_string: int) -> str:
135135
idx_original_string = int(idx_original_string)
136136
except ValueError:
137137
raise TypeError(
138-
(
139-
"The parameter idx_original_string type must be int or passive"
140-
" of cast to int."
141-
)
138+
"The parameter idx_original_string type must be int or passive"
139+
" of cast to int."
142140
)
143141
if idx_original_string < 0:
144142
raise ValueError("The parameter idx_original_string must not be lower than 0.")
145143
if idx_original_string >= len(bwt_string):
146144
raise ValueError(
147-
("The parameter idx_original_string must be lower than" " len(bwt_string).")
145+
"The parameter idx_original_string must be lower than" " len(bwt_string)."
148146
)
149147

150148
ordered_rotations = [""] * len(bwt_string)

data_structures/binary_tree/avl_tree.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
An auto-balanced binary tree!
43
"""

0 commit comments

Comments
 (0)