Python - Convert an array to an ordinary list with the same items Last Updated : 17 Dec, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In Python, we often work with different array-like structures such as arrays, NumPy arrays, or regular lists. Sometimes, we need to convert these arrays to a simple Python list for easier manipulation or compatibility with other functions. Using list() constructorlist() function is the most straightforward way to convert different types of array-like objects into a Python list. It works for regular lists, tuples, and even arrays. Python import array # Example with a regular array a = array.array('i', [1, 2, 3, 4]) # Convert the array to a list using list() b = list(a) # 'b' is now a simple list containing the same elements as 'a' print(b) Output[1, 2, 3, 4] Other methods that we can use to convert an array to a simple list in Python are:Table of ContentUsing tolist() Using List ComprehensionUsing extend()Using tolist() If we are working with a NumPy array, we can use the tolist() method to convert it into a regular Python list. NumPy arrays are commonly used for numerical data and large datasets. Python import numpy as np # Example with a NumPy array a = np.array([1, 2, 3, 4]) # Convert the NumPy array to a list using tolist() b = a.tolist() # 'b' is now a simple Python list containing the same elements as 'a' print(b) Output[1, 2, 3, 4] Using List ComprehensionList comprehension can be used when we want to convert an array-like object to a list while also transforming or filtering the data during the conversion. Python import array # Example with an array.array a = array.array('i', [1, 2, 3, 4]) # Convert to list using list comprehension b = [item for item in a] # 'b' now contains the same items as 'a' print(b) Output[1, 2, 3, 4] Using extend()If we have an existing list and we want to add items from another array-like object (such as array.array or NumPy array), we can use the extend() method. Python import numpy as np # Example with a NumPy array and an empty list a = np.array([1, 2, 3, 4]) b = [] # Use 'extend' to add items from 'a' into 'b' b.extend(a) # 'b' now contains all elements from 'a' print(b) Output[1, 2, 3, 4] Comment More infoAdvertise with us Next Article Python - Convert an array to an ordinary list with the same items T Twinkl Bajaj Follow Improve Article Tags : Misc Python python-list Python list-programs Practice Tags : Miscpythonpython-list Similar Reads How to convert a dictionary into a NumPy array? In this article, we will learn how to convert a Python Dictionary into a numpy array which is more efficient for numerical operations and provides powerful tools for matrix and array manipulationsKey Steps to Convert a Dictionary to a NumPy ArrayUse dict.items(): This returns key-value pairs from th 3 min read How to convert NumPy array to dictionary in Python? The following article explains how to convert numpy array to dictionary in Python. Array in Numpy is a table of elements (usually numbers), all of the same type, indexed by a tuple of positive integers. In Numpy, number of dimensions of the array is called rank of the array. A tuple of integers givi 3 min read NumPy ndarray.tolist() Method | Convert NumPy Array to List The ndarray.tolist() method converts a NumPy array into a nested Python list. It returns the array as an a.ndim-levels deep nested list of Python scalars. Data items are converted to the nearest compatible built-in Python type. Example Python3 import numpy as np gfg = np.array([1, 2, 3, 4, 5]) print 1 min read Convert Python List to numpy Arrays NumPy arrays are more efficient than Python lists, especially for numerical operations on large datasets. NumPy provides two methods for converting a list into an array using numpy.array() and numpy.asarray(). In this article, we'll explore these two methods with examples for converting a list into 4 min read How to convert a list and tuple into NumPy arrays? In this article, let's discuss how to convert a list and tuple into arrays using NumPy. NumPy provides various methods to do the same using Python. Example: Input: [3, 4, 5, 6]Output: [3 4 5 6]Explanation: Python list is converted into NumPy ArrayInput: ([8, 4, 6], [1, 2, 3])Output: [[8 4 6] [1 2 3] 2 min read Like