I have two lists and I am trying to create one big list with them. The first list just gives me all the possible number of children each parent can have. Think of it as labels.
num_of_children = [0, 1, 2, 3, 4, 5]
The second list gives me how many parents have how many children. For example, 27 parents have 0 children, 22 of them have 1, and so on.
number_of_parents = [27, 22, 30, 12, 7, 2]
Using these two lists, I am trying to get a list that looks like this:
parent_num_of_children = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5]
So far I was able to do this with:
for number in num_of_children:
parent_num_of_children.extend([number] * number_of_parents[number])
My question is: Is there another way to get this list without a for loop, just using something like the range function or another clever way?
Thanks for your answers!