I have two lists with same length:
list_1 = [1,2,3,4,5,6]
list_2 = ['a','b','c','d','e','f']
I need to merge these lists based on n as below:
- if n = 1:
result = [1,'a',2,'b',3,'c',4,'d',5,'e',6,'f']
- if n = 2:
result = [1,2,'a','b',3,4,'c','d',5,6,'e','f']
- if n = 3:
result = [1,2,3,'a','b','c',4,5,6,'d','e','f']
- if n = 4:
result = [1,2,3,4,'a','b','c','d',5,6,'e','f']
, and so on
Is there any pythonic way to achieve this? So far I only know to do if n = 1 with list comprehension:
result = [x for sublist in zip(list_1, list_2) for x in sublist]
I don't know how to do it dynamically.