Python | Convert an array to a regular list with the same elements

Python Methods and Functions

Python program for converting an array into a regular list with the same elements.

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 the array to a regular list with the same elements. To do this, we need to use the 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)

Output:

 [45, 34, 67] 




Tutorials