Reputation: 159
I'm using PyCharm to write my code in and then with Jupyter I have to pass some tests required.
However, the same piece of code that provides a perfect working solution in Pycharm produces a keyerror in Juptyer. Is there any reason why? Numpy seems to be working fine...the problem is with my dictionary. The following is the error I am getting:
ipython-input-34-35752ede55c7> in myfunction(input)
56 mydict = {}
57 for s in d:
---> 58 vals = set(sum(units[s],[]))-{s}
59 mydict[s] = vals
60
KeyError: 'A1'
Edit: in PyCharm you can clearly see A1 definitely exists, yet in jupyter apparently A1 does not, the code is identical in both: (please see image of pycharm debugger)
Upvotes: 1
Views: 301
Reputation: 409
Key error usually occurs when python is not able to find the key , from your code it is hard to judge without dictionary what the problem may be about how you have mapped the key.
Upvotes: 1
Reputation: 1163
Hard to say without more data/code, but it seems that 'A1' doesn't exist in whatever you're running in Jupyter. Are you absolutely sure that both the data and the code is the same?
Upvotes: 2