-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnested_arrays.py
More file actions
43 lines (28 loc) · 901 Bytes
/
nested_arrays.py
File metadata and controls
43 lines (28 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
"""Example for a flatten arrays.
Example:
$ python nested_arrays.py
"""
def processor_nested_arrays(narrays):
"""Example function for flatten an array of arbitrarily nested arrays
of integers into a flat array of integers.
Args:
narrays: nested arrays.
Returns:
The return the flat array of integers.
"""
result_array = []
for value in narrays:
if isinstance(value, list):
for item in value:
if isinstance(item, list):
for map_item in item:
result_array.append(map_item)
else:
result_array.append(item)
else:
result_array.append(value)
return result_array
if __name__ == '__main__':
MY_ARRAY = [[1, 2, [3]], 4]
print processor_nested_arrays(narrays=MY_ARRAY)