Python | Convert an array to an ordinary list with the same items
Prerequisite : Array in Python
Python program to convert an array to an ordinary list with the same items.
Examples:
Input : array('i', [1, 3, 5, 3, 7, 1, 9, 3])
Output :[1, 3, 5, 3, 7, 1, 9, 3]
Explanation: the array with elements [1, 3, 5, 3,
7, 1, 9, 3] are converted into list with the
same elements.
Input :array('k', [45, 23, 56, 12])
Output :[45, 23, 56, 12]
Explanation: the array with elements [45, 23, 56,
12] are converted into list with the same elements.
Approach to the problem:
We want to convert an array into an ordinary list with the same items. For doing so we need to use a function
// This function tolist() converts the array into a list. arrayname.tolist()
from array import *def array_list(array_num): num_list = array_num.tolist() # list print(num_list) # driver code array_num = array('i', [45,34,67]) # array array_list(array_num) |
chevron_right
filter_none
Output:
[45, 34, 67]
Recommended Posts:
- Python | Associating a single value with all list items
- Python | Count number of items in a dictionary value that is a list
- Python | Insert the string at the beginning of all items in a list
- Python | Convert list of string into sorted list of integer
- Python | Convert list of numerical string to list of Integers
- Python | Convert list of string to list of list
- Python | Convert list of tuples to list of list
- Python | Convert a nested list into a flat list
- Python | Convert 1D list to 2D list of variable length
- Python | Convert list of tuples to list of strings
- Python | Convert string enclosed list to list
- Python | Convert a string representation of list into list
- Python | Convert list of strings to list of tuples
- Python | Convert given list into nested list
- Python | Convert list of tuples into list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



