편집 기록

편집 기록
  • 프로필 알 수 없는 사용자님의 편집
    날짜2017.10.10

    파이썬 while문 질문


    아래는 너비우선탐색 알고리즘 코드인데요 에러없이 돌아가서 정답은 "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")
    
  • 프로필 편집요청빌런님의 편집
    날짜2017.09.19

    파이썬 while문 질문


    아래는 너비우선탐색 알고리즘 코드인데요 에러없이 돌아가서 정답은 "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")
    
  • 프로필 알 수 없는 사용자님의 편집
    날짜2017.09.19

    파이썬 while문 질문


    아래는 너비우선탐색 알고리즘 코드인데요 에러없이 돌아가서 정답은 "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")