Concatenate two lists index-wise
Write a program to add two lists index-wise. Create a new list that contains the 0th index item from both the list, then the 1st index item, and so on till the last element. any leftover items will get added at the end of the new list.
Given:
Expected output:
['My', 'name', 'is', 'Kelly']
Hint:
Use list comprehension with the
zip()
functionSolution:
Use the
need an explanation for this answer? contact us directly to get an explanation for this answerzip()
function. This function takes two or more iterables (like list, dict, string), aggregates them in a tuple, and returns it.