GeezerVison is showing github.com — Pyupgrade to python3.8 (#3616) · jusing-es/Python@9b95e4f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: DIRECTORY.md +5Lines changed: 5 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 323 | 323 | * [Sdbm](https://github.com/TheAlgorithms/Python/blob/master/hashes/sdbm.py) | 324 | 324 | * [Sha1](https://github.com/TheAlgorithms/Python/blob/master/hashes/sha1.py) | 325 | 325 |
| | 326 | +## Knapsack | | 327 | + * [Knapsack](https://github.com/TheAlgorithms/Python/blob/master/knapsack/knapsack.py) | | 328 | + * [Test Knapsack](https://github.com/TheAlgorithms/Python/blob/master/knapsack/test_knapsack.py) | | 329 | + | 326 | 330 | ## Linear Algebra | 327 | 331 | * Src | 328 | 332 | * [Lib](https://github.com/TheAlgorithms/Python/blob/master/linear_algebra/src/lib.py) | | 502 | 506 | * [Magicdiamondpattern](https://github.com/TheAlgorithms/Python/blob/master/other/magicdiamondpattern.py) | 503 | 507 | * [Markov Chain](https://github.com/TheAlgorithms/Python/blob/master/other/markov_chain.py) | 504 | 508 | * [Max Sum Sliding Window](https://github.com/TheAlgorithms/Python/blob/master/other/max_sum_sliding_window.py) | | 509 | + * [Median Of Two Arrays](https://github.com/TheAlgorithms/Python/blob/master/other/median_of_two_arrays.py) | 505 | 510 | * [Nested Brackets](https://github.com/TheAlgorithms/Python/blob/master/other/nested_brackets.py) | 506 | 511 | * [Palindrome](https://github.com/TheAlgorithms/Python/blob/master/other/palindrome.py) | 507 | 512 | * [Password Generator](https://github.com/TheAlgorithms/Python/blob/master/other/password_generator.py) | |
Collapse file Copy file name to clipboardExpand all lines: ciphers/simple_substitution_cipher.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,7 +18,7 @@ def main(): | 18 | 18 | mode = "decrypt" | 19 | 19 | translated = decryptMessage(key, message) | 20 | 20 |
| 21 | | - print("\n{}ion: \n{}".format(mode.title(), translated)) | | 21 | + print(f"\n{mode.title()}ion: \n{translated}") | 22 | 22 |
| 23 | 23 |
| 24 | 24 | def checkValidKey(key: str) -> None: | |
Collapse file Copy file name to clipboardExpand all lines: ciphers/xor_cipher.py +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -141,14 +141,14 @@ def encrypt_file(self, file: str, key: int = 0) -> bool: | 141 | 141 | assert isinstance(file, str) and isinstance(key, int) | 142 | 142 |
| 143 | 143 | try: | 144 | | - with open(file, "r") as fin: | | 144 | + with open(file) as fin: | 145 | 145 | with open("encrypt.out", "w+") as fout: | 146 | 146 |
| 147 | 147 | # actual encrypt-process | 148 | 148 | for line in fin: | 149 | 149 | fout.write(self.encrypt_string(line, key)) | 150 | 150 |
| 151 | | - except IOError: | | 151 | + except OSError: | 152 | 152 | return False | 153 | 153 |
| 154 | 154 | return True | @@ -166,14 +166,14 @@ def decrypt_file(self, file: str, key: int) -> bool: | 166 | 166 | assert isinstance(file, str) and isinstance(key, int) | 167 | 167 |
| 168 | 168 | try: | 169 | | - with open(file, "r") as fin: | | 169 | + with open(file) as fin: | 170 | 170 | with open("decrypt.out", "w+") as fout: | 171 | 171 |
| 172 | 172 | # actual encrypt-process | 173 | 173 | for line in fin: | 174 | 174 | fout.write(self.decrypt_string(line, key)) | 175 | 175 |
| 176 | | - except IOError: | | 176 | + except OSError: | 177 | 177 | return False | 178 | 178 |
| 179 | 179 | return True | |
Collapse file Copy file name to clipboardExpand all lines: compression/lempel_ziv.py +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,10 +17,10 @@ def read_file_binary(file_path: str) -> str: | 17 | 17 | with open(file_path, "rb") as binary_file: | 18 | 18 | data = binary_file.read() | 19 | 19 | for dat in data: | 20 | | - curr_byte = "{0:08b}".format(dat) | | 20 | + curr_byte = f"{dat:08b}" | 21 | 21 | result += curr_byte | 22 | 22 | return result | 23 | | - except IOError: | | 23 | + except OSError: | 24 | 24 | print("File not accessible") | 25 | 25 | sys.exit() | 26 | 26 |
| @@ -105,7 +105,7 @@ def write_file_binary(file_path: str, to_write: str) -> None: | 105 | 105 |
| 106 | 106 | for elem in result_byte_array: | 107 | 107 | opened_file.write(int(elem, 2).to_bytes(1, byteorder="big")) | 108 | | - except IOError: | | 108 | + except OSError: | 109 | 109 | print("File not accessible") | 110 | 110 | sys.exit() | 111 | 111 |
| |
Collapse file Copy file name to clipboardExpand all lines: compression/lempel_ziv_decompress.py +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,10 +16,10 @@ def read_file_binary(file_path: str) -> str: | 16 | 16 | with open(file_path, "rb") as binary_file: | 17 | 17 | data = binary_file.read() | 18 | 18 | for dat in data: | 19 | | - curr_byte = "{0:08b}".format(dat) | | 19 | + curr_byte = f"{dat:08b}" | 20 | 20 | result += curr_byte | 21 | 21 | return result | 22 | | - except IOError: | | 22 | + except OSError: | 23 | 23 | print("File not accessible") | 24 | 24 | sys.exit() | 25 | 25 |
| @@ -76,7 +76,7 @@ def write_file_binary(file_path: str, to_write: str) -> None: | 76 | 76 |
| 77 | 77 | for elem in result_byte_array[:-1]: | 78 | 78 | opened_file.write(int(elem, 2).to_bytes(1, byteorder="big")) | 79 | | - except IOError: | | 79 | + except OSError: | 80 | 80 | print("File not accessible") | 81 | 81 | sys.exit() | 82 | 82 |
| |
Collapse file Copy file name to clipboardExpand all lines: data_structures/binary_tree/segment_tree_other.py +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | from queue import Queue | 8 | 8 |
| 9 | 9 |
| 10 | | -class SegmentTreeNode(object): | | 10 | +class SegmentTreeNode: | 11 | 11 | def __init__(self, start, end, val, left=None, right=None): | 12 | 12 | self.start = start | 13 | 13 | self.end = end | @@ -17,10 +17,10 @@ def __init__(self, start, end, val, left=None, right=None): | 17 | 17 | self.right = right | 18 | 18 |
| 19 | 19 | def __str__(self): | 20 | | - return "val: %s, start: %s, end: %s" % (self.val, self.start, self.end) | | 20 | + return f"val: {self.val}, start: {self.start}, end: {self.end}" | 21 | 21 |
| 22 | 22 |
| 23 | | -class SegmentTree(object): | | 23 | +class SegmentTree: | 24 | 24 | """ | 25 | 25 | >>> import operator | 26 | 26 | >>> num_arr = SegmentTree([2, 1, 5, 3, 4], operator.add) | |
Collapse file Copy file name to clipboardExpand all lines: data_structures/heap/heap.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #!/usr/bin/python3 | 2 | 2 |
| 3 | 3 |
| 4 | | -class Heap(object): | | 4 | +class Heap: | 5 | 5 | """ | 6 | 6 | >>> unsorted = [103, 9, 1, 7, 11, 15, 25, 201, 209, 107, 5] | 7 | 7 | >>> h = Heap() | |
Collapse file Copy file name to clipboardExpand all lines: data_structures/linked_list/deque_doubly.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,7 +20,7 @@ def __init__(self, link_p, element, link_n): | 20 | 20 | self._next = link_n | 21 | 21 |
| 22 | 22 | def has_next_and_prev(self): | 23 | | - return " Prev -> {0}, Next -> {1}".format( | | 23 | + return " Prev -> {}, Next -> {}".format( | 24 | 24 | self._prev is not None, self._next is not None | 25 | 25 | ) | 26 | 26 |
| |
Collapse file Copy file name to clipboardExpand all lines: graphs/minimum_spanning_tree_boruvka.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -99,7 +99,7 @@ def build(vertices=None, edges=None): | 99 | 99 | g.add_edge(*edge) | 100 | 100 | return g | 101 | 101 |
| 102 | | - class UnionFind(object): | | 102 | + class UnionFind: | 103 | 103 | """ | 104 | 104 | Disjoint set Union and Find for Boruvka's algorithm | 105 | 105 | """ | |
Collapse file Copy file name to clipboardExpand all lines: machine_learning/astar.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 | import numpy as np | 14 | 14 |
| 15 | 15 |
| 16 | | -class Cell(object): | | 16 | +class Cell: | 17 | 17 | """ | 18 | 18 | Class cell represents a cell in the world which have the property | 19 | 19 | position : The position of the represented by tupleof x and y | @@ -45,7 +45,7 @@ def showcell(self): | 45 | 45 | print(self.position) | 46 | 46 |
| 47 | 47 |
| 48 | | -class Gridworld(object): | | 48 | +class Gridworld: | 49 | 49 | """ | 50 | 50 | Gridworld class represents the external world here a grid M*M | 51 | 51 | matrix | |
|