-
Notifications
You must be signed in to change notification settings - Fork 801
Expand file tree
/
Copy pathmy_index_all.py
More file actions
27 lines (26 loc) · 897 Bytes
/
my_index_all.py
File metadata and controls
27 lines (26 loc) · 897 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
def index_all(array, search):
print("array " , array)
tab = []
for i, value in enumerate(array):
if (type(value) == list and value != search):
tabList = []
a = index_all(value, search)
if (a):
for n in a:
if (type(n) == list):
n.append(i)
tabList.append(n)
else:
tabList.append([i,n])
for tabListItem in tabList:
tab.append(tabListItem)
print("ddd tab " , tab, "array " , array, "value" , value, " a = " , a)
else:
if (value == search):
tab.append(i)
print("array " , array, "tab " , tab, "value" , value)
return tab
# example = [[[1, 2, 3], 2, [1, 3]], [1, 2, 3]]
example = [[[1, 2, 3], 2, [1, 3]], [1, 2, 3]]
print(index_all(example, 2)) # [[0, 0, 1], [0, 1], [1, 1]]
print(index_all(example, [1, 2, 3])) # [[0, 0], [1]]