0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Python3]dict.keys()を使用した際にTypeError: unhashable type: 'list' で引っかかりそうになった話

Last updated at Posted at 2019-05-15
再現できるコード
if foo in dict.keys():
...

みたいなことをしようとした時に、下記のエラーが発生した。

ERROR内容
TypeError: unhashable type: 'list' 

下記のように変更して解決した。

解決策
if foo in list(dict.keys()):
...

dict.keys()の戻り値は下記のようになるが、(多分)これが純粋なlistではない故に発生するエラーなのに、エラー内容がTypeError: unhashable type: 'list' というのは分かりづらい…。

dict.keys()の戻り値
dict.keys(['aaa', 'bbb', 'ccc'])
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?