I have three lists as seen below:
a = [0,0,0,0,0,1,1,1,1,1,2,2,2,2]
b = [1,2,3,5,6,7,7,4,3,2,1,2,2,3]
c = [3,4,5,2,5,7,8,2,1,3,4,7,3,8]
I want to append [b,c] to the corresponding index of a new list where a is the index, to clarify what I mean this is the desired result
data = [
[[1,3],[2,4],[3,5],[5,2],[6,5]],
[[7,7],[7,8],[4,2],[3,1],[2,3]],
[[1,4],[2,7],[2,3],[3,8]]
]
As in data[0] = [b,c] where a is 0 and so on..
I am trying to implement this with the following code
n = list(set(a))
data= [[]]*len(n)
cnt = 0
for i in range(len(a)-1):
if a[i] == a[i+1] and a[i] == cnt:
data[cnt].append([b[i],c[i]])
if a[i] != a[i+1] and a[i] == cnt:
data[cnt].append([b[i],c[i]])
cnt += 1
That gives me this answer:
data = [
[[1, 3], [2, 4], [3, 5], [5, 2], [6, 5], [7, 7], [7, 8], [4, 2], [3, 1], [2, 3], [1, 4], [2, 7], [2, 3]],
[[1, 3], [2, 4], [3, 5], [5, 2], [6, 5], [7, 7], [7, 8], [4, 2], [3, 1], [2, 3], [1, 4], [2, 7], [2, 3]],
[[1, 3], [2, 4], [3, 5], [5, 2], [6, 5], [7, 7], [7, 8], [4, 2], [3, 1], [2, 3], [1, 4], [2, 7], [2, 3]]
]
But that doesn't give me the result I am seeking, any help is appreciated!