Working with a nested list works:
L = ['a','b','c','d'] numbers = [2, 4, 3, 1] >>> [x for x, number in zip(L, numbers) for _ in range(number)] ['a', 'a', 'b', 'b', 'b', 'b', 'c', 'c', 'c', 'd']
The "subcycle" for _ in range(number) repeats the value of number times. Here L can contain any object, not just strings.
Example:
L = [[1, 2, 3],'b','c', 'd'] numbers = [2, 4, 3, 1] [x for x, number in zip(L, numbers) for _ in range(number)] [[1, 2, 3], [1, 2, 3], 'b', 'b', 'b', 'b', 'c', 'c', 'c', 'd']
but this aligns the list:
[x for i, j in zip(L, numbers) for x in i*j] [1, 2, 3, 1, 2, 3, 'b', 'b', 'b', 'b', 'c', 'c', 'c', 'd']
not quite the desired result.