[英]Create a list from while loop
I have while loop.我有while循环。 And I want to create a list from while loop.
我想从 while 循环中创建一个列表。 I mean I need to append each result of loop to the list.
我的意思是我需要将循环的每个结果 append 到列表中。 I am sharing my code belog.
我正在分享我的代码。
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=[]
(before the while loop)variableName=[]
(在while循环之前)variableName.append(value)
or variableName+=[value]
variableName.append(value)
或variableName+=[value]
Declared an lst[]
outside of while loop.在 while 循环之外声明了一个
lst[]
。 Then append a
to list.然后 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.