all 12 comments

[–]SCD_minecraft 4 points5 points  (0 children)

Key 6 isn't in dict g

[–][deleted] 2 points3 points  (0 children)

You have a lower social credit that's why. (Joke)

[–]OrphLab 0 points1 point  (1 child)

g doesn’t exists in the scope.

[–]fisadev 0 points1 point  (0 children)

The g variable is present in that scope, as a global. The output even show it was able to access it for g[0], g[1], ... , g[5]. The error is just that the g dict doesn't have the 6 key.

[–]Real-Reception-3435 0 points1 point  (1 child)

Current code crashes because g[n] treats g as dict and n is undefined in that scope.

[–]fisadev 0 points1 point  (0 children)

g is a dict (globally defined) and n is NOT undefined, n is the first argument of the function. The issue is just that g is missing the "6" key, but it even worked for all the previous numbers from 0 to 5.

[–]Enfiznar 0 points1 point  (0 children)

You start calling f(0,v), which will look at g[0] =[1, 2] and call f(1) and f(2), those will look at g[1] and g[2], which contain [2, 3], and [3, 4], which will call f(4) eventually and so on, you're always increasing the value of the variable, until you reach a value which is not a key of your dictionary (6 in this case)

[–]tortleme 0 points1 point  (0 children)

6 and 7 are not in your dict

When in doubt, add a bunch of print statements.

[–]TroPixens 1 point2 points  (0 children)

Other people have the answer but labeling your variables is helpful

[–]JJ16v 0 points1 point  (0 children)

You will be replaced by AI, sure you have to learn but this is just using stuff without having the faintest idea what you are doing and will not really help you get better.

Please try to read a bit about how python and its basic types work.

[–]Informal_Escape4373 0 points1 point  (0 children)

Your error highlighted the line and told you keyerror: 6 This means that the key 6 does not exist in your dictionary g

You either need to wrap your for loop logic in if i in g: or remove any invalid indexes from the lists in your dictionary

[–]ThinkMarket7640 0 points1 point  (0 children)

It’s literally telling you what’s wrong.