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
This commit is contained in:
Matvey
2022-11-19 00:27:29 +03:00
committed by GitHub
parent 3868623fcd
commit 70d4d231bf

View File

@@ -15,20 +15,20 @@ graph["jonny"] = []
def search(name): def search(name):
search_queue = deque() search_queue = deque()
search_queue += graph[name] search_queue += [name]
# This 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 = set() 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.
if person not in searched: if person in searched:
if person_is_seller(person): continue
print(person + " is a mango seller!") if person_is_seller(person):
return True print(person + " is a mango seller!")
else: return True
search_queue += graph[person] search_queue += graph[person]
# Marks this person as searched # Marks this person as searched
searched.add(person) searched.add(person)
return False return False
search("you") search("you")