[Solved] ‘NoneType’ object has no attribute ‘__getitem__’ when I try to return a dict


I don’t see any return statement in the chossen_old_words() function so while you build a dictionary in the function (I suppose it’s the control one), you don’t return it.

When you accept the return value in the next_word() function, as I said the chossen_old_words() function returns nothing. However, in Python every function returns something and if you don’t return anything explicitly (like in your case), then None is returned. Which is exactly what happened to you.

None‘s type is NoneType and it doesn’t have any method. You’re trying to use it as a dictionary though and as soon as you try and retrieve an item from it, you’ll get this error.

I believe this error can be fixed by adding return control statement at the end of the chossen_old_words() function. Hard to say if there are any other errors though.

BTW, your indentation seems to be off.

5

solved ‘NoneType’ object has no attribute ‘__getitem__’ when I try to return a dict