我有一個關于在回圈中呼叫我的函式的問題。
下面是我的代碼:
List_new = myfunction()
for items in List_new:
if(my condition is TRUE):
Execute some commands
if(my condition is FALSE):
recall myfunction()
我的問題是我正在使用 myfunction() 加載“List_new”。當我的條件為 False 時,如何迭代更改“List_new”。我想重新加載該功能,尤其是當條件為 FALSE 時。這意味著我會一直呼叫該函式直到它為 false,然后執行 myfunction() 的最終輸出。
預先感謝您的幫助。
uj5u.com熱心網友回復:
我將假設生成的串列myfunction()是一個恒定大小。
您可以使用 while 回圈:
List_new = myfunction()
index=0
while index < len(List_new):
items = List_new[index]
if(my condition is TRUE):
#Execute some commands
i =1
if(my condition is FALSE):
List_new = myfunction()
請記住,如果myfunction()連續生成錯誤值,此解決方案將具有無限回圈。如果你能保證所有的值最終都會是,True那么它應該總是終止。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/368881.html
上一篇:如何清理/獲取嵌套字典中的資料
下一篇:Python重新匹配字數
