파이썬 while문 질문

조회수 1676회

아래는 너비우선탐색 알고리즘 코드인데요 에러없이 돌아가서 정답은 "Thom"이 나옵니다. 그런데 저기 while문에서 while search_queue:while search_queue == True: 이렇게 쓰면 안되던데 두 구문의 차이가 뭔가요 ㅜㅜ?

graph = {}

graph["you"] = ["alice", "bob", "claire"]

graph["alice"] = ["peggy"]
graph["bob"] = ["anuj", "peggy"]
graph["claire"] = ["thom", "jonny"]

graph["anuj"] = []
graph["peggy"] = []
graph["thom"] = []
graph["jonny"] = []


from collections import deque

def person_is_seller(name):
    return name[-1] == "m"

def search(name):
    search_queue = deque()
    search_queue += graph["you"]
    # print(search_queue)
    searched = []

    while search_queue:
        person = search_queue.popleft()
        if not person in searched:
            if person_is_seller(person):
                print(person + " is mango seller!")
                return True
            else:
                search_queue += graph[person]
                searched.append(person)
    return False

search("you")

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)