如何避免將代碼拆分爲兩個單獨的部分? 我試圖只調用一次「DoSomething _...」函數,但在兩種情況下都可以工作。 我可能會爲此添加更多「for(s)」,問題是我必須處理單獨的代碼部分。如何避免在for + if鏈中重複代碼?
for first in FIRST_LIST:
for second in SECOND_LIST:
for third in THIRD_LIST:
if third!='Some specific thing':
for fourth in FOURTH_LIST:
DoSomething_K_x_fourth_Times(first,second,third,fourth)
else:
forth=0
DoSomething_K_Times(first,second,third,fourth)
'用於闡述FORTH_LIST如果第三=「一些具體的事情」別的[0]:' – jasonharper
四年的序通常被拼寫爲「第四」,而不是「規定」。 「Forth」這個詞的意思是不同的,沿着「前進」的方向。 –
@jasonharper will else [0]分支會執行DoSomething _...嗎? – Elliad