Ask your own question, for FREE!
Mathematics 18 Online
OpenStudy (anonymous):

How do I fix my Python code? The extend method in the last line is throwing exceptions :(

OpenStudy (anonymous):

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

OpenStudy (anonymous):

what exception?

OpenStudy (anonymous):

nonconforming operands or something

OpenStudy (anonymous):

oh wait, are you trying to use a list comprehension? you forgot to put it inside [ and ]

OpenStudy (anonymous):

!!!!!

OpenStudy (anonymous):

it should say frontier([...])

OpenStudy (anonymous):

i mean frontier.extend([ ... ])

OpenStudy (anonymous):

the list comprehension syntax is [item.foo() for item in list]

OpenStudy (anonymous):

hmm now it says ValueError

OpenStudy (anonymous):

ValueError - Need more than 1 value to unpack

OpenStudy (anonymous):

i think that means getSuccessors is returning a single value rather than a list

OpenStudy (anonymous):

can't solve that without more context

OpenStudy (anonymous):

how do I resolve this

OpenStudy (anonymous):

there's no way to know with the information you've given me so far

OpenStudy (anonymous):

I thought getSuccessors returns a list of tuples

OpenStudy (anonymous):

that's a function you wrote, isn't it? i have no idea what it does

OpenStudy (anonymous):

I didn't write this one myself I ripped it from a website

OpenStudy (anonymous):

well either you're using it wrong or the function has a bug

OpenStudy (anonymous):

I think I should stop copy-pasting random code off the internet hoping that one function works :-P

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!