I have this code
from typing import List, Tuple
n = 2
a = [1,3]
b = [2,3]
def zipper(a: List[int], b: List[int]) -> List[int]:
zippy = []
for i in range(len(a)):
zippy.append((a[i], b[i]))
return zippy
print(zipper(a, b))
How can I create a regular list from this?
CodePudding user response:
Sorry, just realised from the title of the post that you want [1, 2, 3, 3]
from [(1, 2), (3, 3)]
:
list(itertools.chain.from_iterable(zipper(a, b)))
>> [1, 2, 3, 3]
CodePudding user response:
Just keep it simple:
for i in range(len(a)):
zippy.append(a[i])
zippy.append(b[i])
You do know there's zip
in python, right?