Skip to content
3 changes: 3 additions & 0 deletions matrix/nth_fibonacci_using_matrix_exponentiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,7 @@ def main():


if __name__ == "__main__":
import doctest

doctest.testmod()
main()
34 changes: 17 additions & 17 deletions matrix/spiral_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,35 @@

Matrix must satisfy below conditions
i) matrix should be only one or two dimensional
ii)column of all the row should be equal
ii) number of column of all rows should be equal
"""

from collections.abc import Iterable

def checkMatrix(a):

def check_matrix(matrix):
# must be
if type(a) == list and len(a) > 0:
if type(a[0]) == list:
prevLen = 0
for i in a:
if prevLen == 0:
prevLen = len(i)
result = True
elif prevLen == len(i):
if matrix and isinstance(matrix, Iterable):
if isinstance(matrix[0], Iterable):
prev_len = 0
for row in matrix:
if prev_len == 0:
prev_len = len(row)
result = True
else:
result = False
result = prev_len == len(row)
else:
result = True
else:
result = False

return result


def spiralPrint(a):

if checkMatrix(a) and len(a) > 0:

if check_matrix(a) and len(a) > 0:
matRow = len(a)
if type(a[0]) == list:
if isinstance(a[0], Iterable):
matCol = len(a[0])
else:
for dat in a:
Expand Down Expand Up @@ -64,5 +63,6 @@ def spiralPrint(a):


# driver code
a = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
spiralPrint(a)
if __name__ == "__main__":
a = ([1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12])
spiralPrint(a)
6 changes: 3 additions & 3 deletions other/fischer_yates_shuffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import random


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