I have two lists:
x = [0,2]
y = [['1','2','1'],['5','5','5','2','1']]
I initialize a new list which should contain two lists:
z = []
I would like list "z" to look like this:
[[0,1,2],[2,3,4,5,6]]
As you can see, both lists inside list "z" has as many 1-incremental elements as the number of elements in list "y". Let me try and be more clear:
you take the first element of list "x", which is 0;
I want to increment that value of 0 by 1, by as many elements as is the number of elements in the first occurrence of list "y": in this example, the first occurrence of list "y" has 3 occurrences, so I'd like to get: [0,1,2]
you take the second element of list "x", which is 2;
I want to increment that value of 2 by 1, by as many elements as is the number of elements in the second occurrence of list "y": in this example, the second occurrence of list "y" has 5 occurrences, so I'd like to get: [2,3,4,5,6]
Then I want to combine the two lists into one list called "z", such that "z" looks like this:
[[0,1,2],[2,3,4,5,6]]
Does the question make sense?
I have tried this code:
x = [0,2]
y = [['1','2','1'],['5','5','5','2','1']]
z = []
l = []
for i in range(len(y)):
z.append(l)
for j in range(len(y[i])):
print(j)
l.append(x[i]+j)
print(z)
But I get this result:
[[0, 1, 2, 2, 3, 4, 5, 6], [0, 1, 2, 2, 3, 4, 5, 6]]
Can anyone help me, please?