-
Notifications
You must be signed in to change notification settings - Fork 0
/
deque.py
31 lines (27 loc) · 875 Bytes
/
deque.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
graph = {}
graph["you"] = ["alice", "bob", "claire"]
graph["bob"] = ["anuj", "peggy"]
graph["alice"] = ["peggy"]
graph["claire"] = ["thom", "jonny"]
graph["anuj"] = []
graph["peggy"] = []
graph["thom"] = []
graph["jonny"] = []
def person_is_seller(name):
return name[-1] == 'm'
from collections import deque
search_queue = deque()
search_queue += graph["you"]
searched = []
def search(name):
search_queue = deque()
search_queue+= graph[name]
while search_queue:
person = search_queue.popleft()
if not person in searched:
if person_is_seller(person):
print(person+" is the person you want")
else:
search_queue += graph[person]
searched.append(person)
print(search('you'))