-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathList.py
More file actions
29 lines (27 loc) · 723 Bytes
/
List.py
File metadata and controls
29 lines (27 loc) · 723 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
#public
def is_array(obj):
return "List" in obj.__class__.__name__
#public
def get_array_rank(array):
if is_array(array):
return 1 + max(get_array_rank(item) for item in array)
else:
return 0
def flatten_to_1d(arr):
result = []
def recursive_flatten(subarray):
for item in subarray:
if is_array(item):
recursive_flatten(item)
else:
result.append(item)
recursive_flatten(arr)
return result
# public
def getValueByKeyObject(keys, objects):
arrKeys, values = [], []
for k in keys:
if k in objects.keys():
arrKeys.append(k)
values.append(objects[k])
return arrKeys, values