107
Implementing the algorithm
Implementing the algorithm
To recap, here’s how the implementation will work.
Make a queue to start. In Python, you use the double-ended queue
(
deque
) function for this:
from collections import deque
search_queue = deque()
search_queue += graph[“you”]
Remember,
graph
[
“you”
] will give you a list of all your
neighbors, like [
“alice”, “bob”, “claire”
]. Those all get
added to the search queue.
Creates a new queue
Dostları ilə paylaş: