Python - Interleave multiple lists of same length Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report When we interleave multiple lists, we mix the items from each list so that they alternate in a new sequence. This is often done when we have lists of the same length and want to combine them, with each item from each list appearing one after another. In this article, we will explore interleaving multiple lists of the same length. Using itertools.chain() itertools.chain() efficiently interleaves multiple lists of the same length in one pass, with O(n) time and space complexity for optimal performance.Example: Python import itertools a = [1, 4, 5] b = [3, 8, 9] # Interleave using itertools.chain() res = list(itertools.chain(*zip(a, b))) print(res) Output[1, 3, 4, 8, 5, 9] Explanation:This code pairs elements from lists a and b together.Flattens the pairs, creating a single interleaved list res.Let's explore more methods to interleave multiple lists of same length.Table of ContentUsing List Comprehension Using numpyUsing itertools.chain.from_iterable()Using List Comprehension List comprehension is an efficient way to interleave multiple lists of the same length, flattening the grouped elements into a single sequence.Example: Python a = [1, 4, 5] b = [3, 8, 9] # Interleave using list comphrehension res = [i for sublist in zip(a, b) for i in sublist] print(res) Output[1, 3, 4, 8, 5, 9] Explanation:This pairs elements from lists a and b.Flattens these pairs into an interleaved list.Using numpynumpy provides an efficient way to interleave multiple lists of the same length by stacking them into a 2D array and then flattening it. This method is particularly fast for large numerical datasets due to numpy's optimized operations.Example: Python import numpy as np a = [1, 4, 5] b = [3, 8, 9] # Interleave using numpy res = np.ravel(np.column_stack((a, b))) print(res) Output[1 3 4 8 5 9] Explanation:This stacks the lists into a 2D array.Flattens it into 1D array, interleaving the elements.Using itertools.chain.from_iterable()itertools.chain.from_iterable flattens the result of zip without using extra memory. It's perfect for interleaving multiple lists of the same length, especially with large datasets.Example: Python import itertools a = [1, 4, 5] b = [3, 8, 9] # Interleave using itertools.chain.from_iterable res = list(itertools.chain.from_iterable(zip(a, b))) print(res) Output[1, 3, 4, 8, 5, 9] Explanation:This pairs elements from a and b.Flattens the pairs into single list. Comment More infoAdvertise with us Next Article Python - Append Multiple Lists at Once M manjeet_04 Follow Improve Article Tags : Python Python Programs python-list Python list-programs Practice Tags : pythonpython-list Similar Reads Python | Intersection of multiple lists Given two list of lists, write a Python program to find the intersection between the given two lists. Examples: Input : lst1 = [['a', 'c'], ['d', 'e']] lst2 = [['a', 'c'], ['e', 'f'], ['d', 'e']] Output : [['a', 'c'], ['d', 'e']] Input : lst1 = [[1, 5, 7], [2, 3], [6, 9], [4, 8]] lst2 = [[9, 3], [2, 5 min read Python - Interleave two lists of different length Given two lists of different lengths, the task is to write a Python program to get their elements alternatively and repeat the list elements of the smaller list till the larger list elements get exhausted. Examples: Input : test_list1 = ['a', 'b', 'c'], test_list2 = [5, 7, 3, 0, 1, 8, 4] Output : [' 3 min read Python | Initializing multiple lists In real applications, we often have to work with multiple lists, and initialize them with empty lists hampers the readability of code. Hence a one-liner is required to perform this task in short so as to give a clear idea of the type and number of lists declared to be used. Method #1: Using loops We 4 min read Convert List of Tuples To Multiple Lists in Python When working with data in Python, it's common to encounter situations where we need to convert a list of tuples into separate lists. For example, if we have a list of tuples where each tuple represents a pair of related data points, we may want to split this into individual lists for easier processi 3 min read Python - Append Multiple Lists at Once Our task is to merge multiple lists into a single list by appending all their elements. For example, if the input is a = [1, 2], b = [3, 4], and c = [5, 6], the output should be [1, 2, 3, 4, 5, 6].Using itertools.chain()itertools.chain() function from the itertools module is another way to combine l 4 min read Python - List of tuples to multiple lists Converting a list of tuples into multiple lists involves separating the tuple elements into individual lists. This can be achieved using methods like zip(), list comprehensions or loops, each offering a simple and efficient way to extract and organize the data.Using zip()zip() function is a concise 3 min read Like