I have a list of numbers and a list of strings
a = ['2', '2', '3', '4']
b = [' ', 'A', 'B', 'C']
I want to duplicate each string in b a times making my output look like:
[' ', ' ', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'C']
I’ve tried using map a bunch of different ways. Also would this be easier to do if I just switched the lists to numpy arrays and dealing it with that package.
>Solution :
You can use a list comprehension, you will need to cast the string-version of your numbers to integers though using map(int, a).
[z for x,y in zip(map(int,a), b) for z in x*y]