[fixed] unused variable, standalone running, import doctest module (#… · coderjack/algorithms-in-python@8e5c353 · GitHub
Skip to content

Commit 8e5c353

Browse files
slowy07cclauss
andauthored
[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 <slowy.arfy@gmail.com> * Update other/fischer_yates_shuffle.py Co-authored-by: Christian Clauss <cclauss@me.com> * [fixed] change to tuple and fixing callfunction Signed-off-by: slowy07 <slowy.arfy@gmail.com> * Update matrix/spiral_print.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update matrix/spiral_print.py Co-authored-by: Christian Clauss <cclauss@me.com> * fixing Co-authored-by: Christian Clauss <cclauss@me.com> * [fixed] sprial matrix Signed-off-by: slowy07 <slowy.arfy@gmail.com> * Update spiral_print.py * Update spiral_print.py * Update spiral_print.py * Update spiral_print.py Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent 46e56fa commit 8e5c353

3 files changed

Lines changed: 23 additions & 20 deletions

File tree

matrix/nth_fibonacci_using_matrix_exponentiation.py

Lines changed: 3 additions & 0 deletions

matrix/spiral_print.py

Lines changed: 17 additions & 17 deletions
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)

other/fischer_yates_shuffle.py

Lines changed: 3 additions & 3 deletions

0 commit comments

Comments
 (0)