我是编程初学者,并开始使用Python作为学习它的方法。我目前正在研究一组用于循环()和while循环()的行。 目前我有这个:
def missingDoor(trapdoor,roomwidth,roomheight,step):
safezone = []
hazardflr = givenSteps(roomwidth,step,True)
safetiles = []
for i,m in enumerate(hazardflr):
safetiles.append((m,step))
while i < len(safetiles):
nextSafe = safetiles[i]
if knownSafe(roomwidth, roomheight, nextSafe[0], nextSafe[1]):
if trapdoor[nextSafe[0]/roomwidth][nextSafe[0]%roomwidth] is "0":
if nextSafe[0] not in safezone:
safezone.append(nextSafe[0])
for e in givenSteps(roomwidth,nextSafe[0],True):
if knownSafe(roomwidth, roomheight, e, nextSafe[0]):
if trapdoor[e/roomwidth][e%roomwidth] is "0" and (e,nextSafe[0]) not in safetiles:
safetiles.append((e,nextSafe[0]))
i += 1
return sorted(safezone)
然后在社区成员的帮助下,我能够更有效地将公共变量nextSafe[0]设置为ns,并从顶部调用它:
^{pr2}$这些都取代了价值效率,但有没有其他方法可以让这种效率更高,并可能节省线路?knownSafe(),givenSteps()函数来自另一个使用此代码的代码来查找可能的安全区域和knownsteps。但我的问题是如何使这段代码更有效率,因为最初我开始使用while loops()并发现在给定已知列表时for循环更好。我一直在尝试各种各样的事情,因为我对编程还不熟悉。在
提前谢谢你!!在
所以。。你想要代码复查吗?Here..
不管怎样,我会尽力帮助你的。
代码
说明
希望这有帮助;) 注意,使用“is'0”进行检查不是一个好的做法,更好的做法是:“=='0'”
相关问题 更多 >
编程相关推荐