0

I have 3 lists

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

I want to merge those list to a new list element-wise but have not found a way to do so. The only way I found is with zip() but then I get a tuple. But it should not be a tuple.

Desired output:

new_list = [1,3,6,2,4,7,3,5,8]

How can I achieve that?

With list(zip(a,b,c)) I get [(1,3,6),(2,4,7),(3,5,8)]. I don't want that.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Haidepzai
  • 764
  • 1
  • 9
  • 22

1 Answers1

2
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)
Feras Alfrih
  • 492
  • 3
  • 11