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()

filter_none

edit
close

play_arrow

link
brightness_4
code

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


Output:

[45, 34, 67]
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.