33from operator import add , concat , iconcat
44
55
6- def flatten_comprehension (matrix ):
7- return [item for row in matrix for item in row ]
6+ def flatten_extend (matrix ):
7+ flat = []
8+ for row in matrix :
9+ flat .extend (row )
10+ return flat
811
912
1013def flatten_concatenation (matrix ):
@@ -14,17 +17,18 @@ def flatten_concatenation(matrix):
1417 return flat
1518
1619
17- def flatten_extend (matrix ):
18- flat = []
19- for row in matrix :
20- flat .extend (row )
21- return flat
20+ def flatten_comprehension (matrix ):
21+ return [item for row in matrix for item in row ]
2222
2323
24- def flatten_itertools_chain (matrix ):
24+ def flatten_chain (matrix ):
2525 return list (chain .from_iterable (matrix ))
2626
2727
28+ def flatten_reduce_lambda (matrix ):
29+ return list (reduce (lambda x , y : x + y , matrix , []))
30+
31+
2832def flatten_reduce_add (matrix ):
2933 return reduce (add , matrix , [])
3034
@@ -37,9 +41,5 @@ def flatten_reduce_iconcat(matrix):
3741 return reduce (iconcat , matrix , [])
3842
3943
40- def flatten_reduce_lambda (matrix ):
41- return list (reduce (lambda x , y : x + y , matrix , []))
42-
43-
4444def flatten_sum (matrix ):
4545 return sum (matrix , [])
0 commit comments