Hi
The Unit test cases passed. The grader is failing it with an error that clearly would have failed the unit tests.
Unable to understand what is going on.
Grader error looks as under:
Failed test case: dijkstra_fixed thrown an exception with graph = defaultdict(<class ‘list’>, {0: [[1, 2], [2, 1], [3, 9]…
Expected:
dijkstra_fixed must run without exceptions,
but got:
name ‘defaultdict’ is not defined.
So why is defaultdict
defined in the unit tests but not in the grader?
Or why is it needed in the unit tests?
ChatGPT says (as usual for LLMs, grains of salt):
defaultdict
is a special dictionary-like container provided by thecollections
module in Python. It is a subclass of the built-indict
, but with a key difference: it provides a default value for missing keys using a factory function.When you try to access a key that does not exist in the dictionary, instead of raising a
KeyError
,defaultdict
automatically creates an entry using the default factory function provided during initialization.
Weird but it’s Python.
wow, does this mean i have to do away with using defaultdict in the fixed version?
I don’t know - maybe. Is it hard to do?
nope :). thanks for the guidance.
I am still struggling (I’ve been for hours!) with this issue. My code works but the unittest fails misesably.
Error: Failed test case: dijkstra_fixed thrown an exception with graph = defaultdict(<class ‘list’>, …Expected: dijkstra_fixed must run without exceptions
Got: cannot unpack non-iterable NoneType object
It’s frustrating!!! Please a hint will be appreciated, otherwise I’d have to abandon course.
Hmm, unfortunately I am not taking this course currently, so I cannot help directly.
I solved the issue. I was just confused between the “code” and the “code_fixed” cells. I was not doing the changes in the “code_fixed” one.
Cheers!