Python program to convert an array to an ordinary list with the same items


The array is given. Our task is to convert an array to an ordinary list. We solve this problem with the help of tolist() function. This function return the array as a (possibly nested) list.

Algorithm

Step 1: Given an array.
Step 2: convert the array to a list using tolist() function.
Step 3: Display list

Example Code

#Python program to convert an array to an ordinary
#list with the same items
from array import *
def arraytolist(A): 
   lst = A.tolist() # list
   print("The List Is ::>",lst) 
# Driver code 
A= array('i', [20,30,60]) # array 
arraytolist(A) 

Output

The List Is ::> [20, 30, 60]
The List Is ::> [20, 30, 60]

Updated on: 30-Jul-2019

122 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements