0
1

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 3 years have passed since last update.

pythonで辞書型のkeyに配列は使えるか?

Posted at

pythonで辞書型のkeyに配列を使いたい

競技プログラミングをやっていると、配列と値をハッシュテーブルで紐付けたいことがあります。(ex. 辞書型に[1,2]と入れると"s"と返ってくるようなもの)

いつもlistをkeyにしようとして、怒られてpythonでは辞書型のkeyに配列って使えなかったっけ?となるのでメモ。

結論としてはlistではなくtupleを使えばできます。
動作としてはこんな感じ。


d = {}
d[(1,2)] = "s"
print(d)

# {(1, 2): "s"}

0
1
0

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?