From c1c68d9d2a54c2ecfe38943e64793f17b7d9ade6 Mon Sep 17 00:00:00 2001 From: Dani El-Ayyass Date: Sun, 14 Mar 2021 18:39:59 +0300 Subject: [PATCH] improve 01_breadth-first_search.py (#195) --- 06_breadth-first_search/python/01_breadth-first_search.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/06_breadth-first_search/python/01_breadth-first_search.py b/06_breadth-first_search/python/01_breadth-first_search.py index 4fefda8..47dd8d4 100644 --- a/06_breadth-first_search/python/01_breadth-first_search.py +++ b/06_breadth-first_search/python/01_breadth-first_search.py @@ -16,8 +16,8 @@ graph["jonny"] = [] def search(name): search_queue = deque() search_queue += graph[name] - # This array is how you keep track of which people you've searched before. - searched = [] + # This is how you keep track of which people you've searched before. + searched = set() while search_queue: person = search_queue.popleft() # Only search this person if you haven't already searched them. @@ -28,7 +28,7 @@ def search(name): else: search_queue += graph[person] # Marks this person as searched - searched.append(person) + searched.add(person) return False search("you")