나는 이것을 풀려고한다 : CodeEval.파이썬 : 이상한 루프 동작
문제는 가능한 XY 좌표의 후보 목록을 통과해야합니다. 그런 다음 요구 사항을 충족하면이를 "확인 된"목록에 추가 한 다음 주변 지점을 "tosearch"목록에 추가합니다. 그러나 이것은 내가 기대하는대로 행동하지 않습니다.
예제 코드 :
Starting point
tosearch=[[0,0]]
for point in tosearch:
if conditions filled:
confirmed.append(point)
#Basically Im trying to add (x,y-1) etc. to the tosearct list
tosearch.append([point[0],point[1]-1]) #1
tosearch.append([point[0]+1,point[1]]) #2
tosearch.append([point[0]-1,point[1]-1])#3
tosearch.append([point[0],point[1]+1]) #4
tosearch.remove(point)
else:
tosearch.remove(point)
이 항상 추가의 절반을 무시 될 것으로 보인다. 따라서이 경우 # 1과 # 3은 무시됩니다. 만약 내가 단지 1을 남기면 & 2가 실행될 것입니다. 그것을 반복하는 동안 컬렉션을 수정하고 Pastebin
수정하는 동안 목록을 반복하고 있습니다. 그러지 마. –