K
K
Kamil2K2020-06-23 11:51:58
Python
Kamil2K, 2020-06-23 11:51:58

Why does Python throw an unhashable type: 'dict' error?

Python throws an error unhashable type: 'dict'.
Here is the code that is causing the problem:

def delete_product(user_group, shop = shop, **products):
    if user_group in shop:
        shop[user_group].pop(products)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2020-06-23
@trapwalker

You are trying to use a non-hashable type as a key in the dictionary (in this case, judging by the error, the user_group dictionary is also).
A dictionary key can only be a hashable type, such as a tuple (no nested non-hashable elements), a string, a number, and so on.
Please treat the people on this resource with respect: format the code with tags and include the full stack trace of errors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question