How to simplify and automate the following syntax so that i can achieve:

Assumptions:

- lenght of x and y will alway be the same
- the number of value in x and y will change

Objective:

- print the value in y according to the corresponding number of time that show in x

Expected Output>>> [‘a’, ‘a’, ‘b’, ‘b’, ‘b’, ‘c’]

v = len(x) x = [2, 3, 1] y = ['a', 'b', 'c'] z = [] for i in range(x[0]): z.append(y[0]) for i in range(x[1]): z.append(y[1]) for i in range(x[2]): z.append(y[2])

#if there there is forth value being added in both x and y, then it should repeat the step above#

print(z)

## Answer

You can use nested loop to do this:

x = [2, 3, 1] y = ['a', 'b', 'c'] z = [] v = len(x) for i in range(v): for j in range(x[i]): z.append(y[i]) print(z)