diff --git a/mat_flat.py b/mat_flat.py new file mode 100644 index 0000000..4ce789c --- /dev/null +++ b/mat_flat.py @@ -0,0 +1,19 @@ + +from typing import List +""" +Flattens a 2D list (matrix) into a 1D list. +Args: + M (List[List]): A two-dimensional list to be flattened. +Returns: + List: A one-dimensional list containing all elements of the input matrix in row-major order. +Example: + >>> flatten([[1, 2], [3, 4]]) + [1, 2, 3, 4] + +NOTE: If you add the mat_flat module to a project, call it with mat_flat.flatten(M). + +""" + +def flatten(M: List[List])-> List: + flat = [elem for row in M for elem in row] + return flat \ No newline at end of file