From 2a70358c166f32ea18fdfb20853b6242414dfc4a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 5 Feb 2019 17:20:46 +0100 Subject: move flatten to utils --- lib/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/utils.py') diff --git a/lib/utils.py b/lib/utils.py index 4208c3a..2cf31be 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -21,6 +21,14 @@ def float_or_nan(n): except ValueError: return np.nan +def flatten(somelist): + """ + Flatten a list. + + Example: flatten([[1, 2], [3], [4, 5]]) -> [1, 2, 3, 4, 5] + """ + return [item for sublist in somelist for item in sublist] + def param_slice_eq(a, b, index): """ Check if by_param keys a and b are identical, ignoring the parameter at index. -- cgit v1.2.3