[英]Create a list from while loop
我有while循環。 我想從 while 循環中創建一個列表。 我的意思是我需要將循環的每個結果 append 到列表中。 我正在分享我的代碼。
length = len(filtered)
i = 0
# Iterating using while loop
while i < length-1:
a = filtered[i+1][0], (float(filtered[i+1][1])-float(filtered[i][1]))/(float(filtered[i][1]))
listt=list(a)
i += 1
print(listt)
variableName=[]
(在while循環之前)variableName.append(value)
或variableName+=[value]
在 while 循環之外聲明了一個lst[]
。 然后 append a
列。
length = len(filtered)
i = 0
# Iterating using while loop
lst = []
while i < length-1:
a = (filtered[i+1][0], (float(filtered[i+1][1]) -float(filtered[i][1]))/(float(filtered[i][1])))
lst.append(a)
i += 1
print(lst)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.