I’m trying to run a program which is effectively doing the following:
if [4, 5, False, False, False, False] in {}
And, on this line, I’m getting a TypeError: unhashable type 'list'
What am I doing wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The code
if foo in {}checks if any of the keys of the dictionary is equal tofoo.In your example,
foois a list. A list is an unhashable type, and cannot be the key of a dictionary.If you want to check if any entry of a list is contained in a dictionaries’ keys or in a set, you can try:
if any([x in {} for x in (4, 5, False)]).If you want to check if any of your values is equal to your list, you can try:
if any([v == [4, 5, False, False, False, False] for v in your_dict.values()])