From 70d4d231bfa749dd2f0d5e59d0a139e99dde9949 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sat, 19 Nov 2022 00:27:29 +0300 Subject: [PATCH] Fix/Python 06 bfs: case when entrypoint is target (#203) * Simplify cognitive complexity * Fix case when entrypoint is target * Simplyfy check for case: entrypoint is target --- .../python/01_breadth-first_search.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 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 47dd8d4..0624f4e 100644 --- a/06_breadth-first_search/python/01_breadth-first_search.py +++ b/06_breadth-first_search/python/01_breadth-first_search.py @@ -15,20 +15,20 @@ graph["jonny"] = [] def search(name): search_queue = deque() - search_queue += graph[name] + search_queue += [name] # 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. - if person not in searched: - if person_is_seller(person): - print(person + " is a mango seller!") - return True - else: - search_queue += graph[person] - # Marks this person as searched - searched.add(person) + if person in searched: + continue + if person_is_seller(person): + print(person + " is a mango seller!") + return True + search_queue += graph[person] + # Marks this person as searched + searched.add(person) return False search("you")