簡體   English   中英

如何使用python將數組存儲在新數組中

[英]how do you store an array within a new array using python

我正在遍歷數組中存儲的數字列表,如果它們小於10,我想將它們存儲在新數組中。 到目前為止,這是我嘗試過的。

num = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
i []
for index in range(len(num)):
    if num[index] < 10:
            i = [num[index]]
            for index in range(len(i)):
                print i[index]
num = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
result = [x for x in num if x<10]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM