Skip to content

Commit 615cc09

Browse files
slowy07cclauss
authored andcommitted
[fixed] unused variable, standalone running, import doctest module (TheAlgorithms#4673)
* [fixed] unused variable, standalone running, import doctest module information [standalone running](https://www.geeksforgeeks.org/what-does-the-if-__name__-__main__-do/) Signed-off-by: slowy07 <[email protected]> * Update other/fischer_yates_shuffle.py Co-authored-by: Christian Clauss <[email protected]> * [fixed] change to tuple and fixing callfunction Signed-off-by: slowy07 <[email protected]> * Update matrix/spiral_print.py Co-authored-by: Christian Clauss <[email protected]> * Update matrix/spiral_print.py Co-authored-by: Christian Clauss <[email protected]> * fixing Co-authored-by: Christian Clauss <[email protected]> * [fixed] sprial matrix Signed-off-by: slowy07 <[email protected]> * Update spiral_print.py * Update spiral_print.py * Update spiral_print.py * Update spiral_print.py Co-authored-by: Christian Clauss <[email protected]>
1 parent 0202859 commit 615cc09

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

Diff for: matrix/nth_fibonacci_using_matrix_exponentiation.py

+3
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,7 @@ def main():
8888

8989

9090
if __name__ == "__main__":
91+
import doctest
92+
93+
doctest.testmod()
9194
main()

Diff for: matrix/spiral_print.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,35 @@
44
55
Matrix must satisfy below conditions
66
i) matrix should be only one or two dimensional
7-
ii)column of all the row should be equal
7+
ii) number of column of all rows should be equal
88
"""
99

10+
from collections.abc import Iterable
1011

11-
def checkMatrix(a):
12+
13+
def check_matrix(matrix):
1214
# must be
13-
if type(a) == list and len(a) > 0:
14-
if type(a[0]) == list:
15-
prevLen = 0
16-
for i in a:
17-
if prevLen == 0:
18-
prevLen = len(i)
19-
result = True
20-
elif prevLen == len(i):
15+
if matrix and isinstance(matrix, Iterable):
16+
if isinstance(matrix[0], Iterable):
17+
prev_len = 0
18+
for row in matrix:
19+
if prev_len == 0:
20+
prev_len = len(row)
2121
result = True
2222
else:
23-
result = False
23+
result = prev_len == len(row)
2424
else:
2525
result = True
2626
else:
2727
result = False
28+
2829
return result
2930

3031

3132
def spiralPrint(a):
32-
33-
if checkMatrix(a) and len(a) > 0:
34-
33+
if check_matrix(a) and len(a) > 0:
3534
matRow = len(a)
36-
if type(a[0]) == list:
35+
if isinstance(a[0], Iterable):
3736
matCol = len(a[0])
3837
else:
3938
for dat in a:
@@ -64,5 +63,6 @@ def spiralPrint(a):
6463

6564

6665
# driver code
67-
a = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
68-
spiralPrint(a)
66+
if __name__ == "__main__":
67+
a = ([1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12])
68+
spiralPrint(a)

Diff for: other/fischer_yates_shuffle.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import random
99

1010

11-
def FYshuffle(list):
12-
for i in range(len(list)):
11+
def fisher_yates_shuffle(data: list) -> list:
12+
for _ in range(len(list)):
1313
a = random.randint(0, len(list) - 1)
1414
b = random.randint(0, len(list) - 1)
1515
list[a], list[b] = list[b], list[a]
@@ -21,4 +21,4 @@ def FYshuffle(list):
2121
strings = ["python", "says", "hello", "!"]
2222
print("Fisher-Yates Shuffle:")
2323
print("List", integers, strings)
24-
print("FY Shuffle", FYshuffle(integers), FYshuffle(strings))
24+
print("FY Shuffle", fisher_yates_shuffle(integers), fisher_yates_shuffle(strings))

0 commit comments

Comments
 (0)