how can you merge lists element-wise to a new flat list duplicated?

a = [1, 2, 3]
b = [3, 4, 5]
c = [6, 7, 8]

new_list = []
for n in range(len(a)):
    new_list.append(a[n])
    new_list.append(b[n])
    new_list.append(c[n])

print(new_list)

a more pythonic approach as @Pranav Hosangadi suggested:

a = [1, 2, 3]
b = [3, 4, 5]
c = [6, 7, 8]

new_list = []
n = 0
for x, y, z in zip(a, b, c):
    new_list.append(x)
    new_list.append(y)
    new_list.append(z)

print(new_list)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top