How do I fix my Python code? The extend method in the last line is throwing exceptions :(
frontier = [[problem.getStartState()]] explored = set() while frontier: node = frontier.pop() if problem.isGoalState(node): return node explored.update(node) print node frontier.extend(child for child in problem.getSuccessors(node) if child not in explored and child not in frontier) return None
what exception?
nonconforming operands or something
oh wait, are you trying to use a list comprehension? you forgot to put it inside [ and ]
!!!!!
it should say frontier([...])
i mean frontier.extend([ ... ])
the list comprehension syntax is [item.foo() for item in list]
hmm now it says ValueError
ValueError - Need more than 1 value to unpack
i think that means getSuccessors is returning a single value rather than a list
can't solve that without more context
how do I resolve this
there's no way to know with the information you've given me so far
I thought getSuccessors returns a list of tuples
that's a function you wrote, isn't it? i have no idea what it does
I didn't write this one myself I ripped it from a website
well either you're using it wrong or the function has a bug
I think I should stop copy-pasting random code off the internet hoping that one function works :-P
Join our real-time social learning platform and learn together with your friends!