This nested for loop accomplishes my goal but I would like to do it using list comprehension and/or lambda func
new_a=[]
new_b=[]
a=[1,2,3]
b=[1,2,3]
for num_a in a:
for num_b in b:
new_a.append(num_a)
new_b.append(num_b)
print(new_a)
print(new_b)
output:
new_a=[1, 1, 1, 2, 2, 2, 3, 3, 3]
new_b=[1, 2, 3, 1, 2, 3, 1, 2, 3]
I can get new_a with [num for num in a for num in b]
but can't figure out how to get new_b using listcomp or lambda
new_b = b * len(a)[num_b for num_a in a for num_b in b]?new_a, if you wanted to usenumpy:np.repeat([1,2,3], 3).itertools.permutations