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]
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Java 指令碼
PHP