From 7dd801985e1b6ac20d1b14805b8ab526d308ce96 Mon Sep 17 00:00:00 2001 From: Donald Calloway Date: Thu, 2 Oct 2025 09:47:18 -0700 Subject: [PATCH] Added mat_flat module utility file --- mat_flat.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 mat_flat.py 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