Python图形算法问题,我的代码出了什么问题



这是我在这里的第一个问题,我正在努力学习算法。你能告诉我我的代码出了什么问题吗?感谢所有善意的回应。

这是代码:

from collections import deque
graph ={}
graph["you"] = ["Mark", "Victoria", "Lovie", "Chi","John"]
def personIsSeller(name):
return name[-1] == 'M'
def search(name):
searchQueue = deque()
searchQueue += graph[name]
searched = []
while searchQueue:
person = searchQueue.popleft()
if not person in searched:
if personIsSeller(person):
print(person, "is a mango-seller")
return True
else:
searchQueue += graph[person]
searched.append(person)
return False
search("you")
def personIsSeller(name):
return name[0] == 'M

基本上,我改变了personIsSeller的索引,现在它正在发挥作用,我是社区中的一个新成员,感谢@Andrew,他让我改变了处理问题的方法。

最新更新