Python - Convert an array to an ordinary list with the same items Last Updated : 17 Dec, 2024 Comments Improve Suggest changes 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? It's sometimes required to convert a dictionary in Python into a NumPy array and Python provides an efficient method to perform this operation. Converting a dictionary to NumPy array results in an array holding the key-value pairs in the dictionary. Python provides numpy.array() method to convert a 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 Pandas Series to Python list? In this article, we will discuss how to convert a Pandas series to a Python List and it's type. This can be done using the tolist() method.Example 1: Python3 import pandas as pd evenNumbers = [2, 4, 6, 8, 10] evenNumbersDs = pd.Series(evenNumbers) print("Pandas Series and type") print(evenNumbersDs) 2 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 Python | Ways to Convert a 3D list into a 2D list List is a common type of data structure in Python. While we have used the list and 2d list, the use of 3d list is increasing day by day, mostly in case of web development. Given a 3D list, the task is to convert it into a 2D list. These type of problems are encountered while working on projects or w 3 min read How to convert NumPy array to list ? This article will guide you through the process of convert a NumPy array to a list in Python, employing various methods and providing detailed examples for better understanding. Convert NumPy Array to List There are various ways to convert NumPy Array to List here we are discussing some generally us 4 min read Python - Convert list of string to list of list In Python, we often encounter scenarios where we might have a list of strings where each string represents a series of comma-separated values, and we want to break these strings into smaller, more manageable lists. In this article, we will explore multiple methods to achieve this. Using List Compreh 3 min read Convert Python Nested Lists to Multidimensional NumPy Arrays Prerequisite: Python List, Numpy ndarray Both lists and NumPy arrays are inter-convertible. Since NumPy is a fast (High-performance) Python library for performing mathematical operations so it is preferred to work on NumPy arrays rather than nested lists. Method 1: Using numpy.array(). Approach : Im 2 min read Like