improve 01_breadth-first_search.py (#195)
This commit is contained in:
@@ -16,8 +16,8 @@ graph["jonny"] = []
|
|||||||
def search(name):
|
def search(name):
|
||||||
search_queue = deque()
|
search_queue = deque()
|
||||||
search_queue += graph[name]
|
search_queue += graph[name]
|
||||||
# This array is how you keep track of which people you've searched before.
|
# This is how you keep track of which people you've searched before.
|
||||||
searched = []
|
searched = set()
|
||||||
while search_queue:
|
while search_queue:
|
||||||
person = search_queue.popleft()
|
person = search_queue.popleft()
|
||||||
# Only search this person if you haven't already searched them.
|
# Only search this person if you haven't already searched them.
|
||||||
@@ -28,7 +28,7 @@ def search(name):
|
|||||||
else:
|
else:
|
||||||
search_queue += graph[person]
|
search_queue += graph[person]
|
||||||
# Marks this person as searched
|
# Marks this person as searched
|
||||||
searched.append(person)
|
searched.add(person)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
search("you")
|
search("you")
|
||||||
|
|||||||
Reference in New Issue
Block a user