Given two lists, I want to merge them so that all elements from the first list are even-indexed (preserving their order) and all elements from second list are odd-indexed (a
It can be done with slicing. Do count and slice in terminal:
count
slice
>>> list1=['Apple','Mango','Orange'] >>> list2=['One','Two','Three'] >>> list = [None]*(len(list1)+len(list2)) >>> list[::2] = list1 >>> list[1::2] = list2 >>> list
Output:
['Apple', 'One', 'Mango', 'Two', 'Orange', 'Three']