Python 程式將陣列轉換為具有相同元素的普通列表


給定一個數組。我們的任務是將陣列轉換為普通列表。我們藉助 tolist() 函式解決該問題。該函式返回陣列作為(可能巢狀的)列表。

演算法

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

示例程式碼

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

輸出

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

更新於: 30-Jul-2019

131 檢視

開啟您的職涯

完成課程以取得認證

開始使用
廣告
© . All rights reserved.