1
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: 配列(リスト)をインデックス付きで表示するTips (配列の要素が何番目にあるか調べる方法)

Last updated at Posted at 2020-07-16

やりたいこと

Pythonで、配列とかが長いとき、自分が取得したいのが何番目にあるかぱっとわからないことがある。
(表とかの列で何列目とってくればいいとか考えるとき)
ググってもあまり出てこなかったのでメモ。

コマンド

print([str(i) + ": " + x for i,x in enumerate( YOUR_LIST )])

リスト内包表記 + enumerateでできる!

Example

list = ["A", "B", "C", "D"]
print([str(i) + ": " + x for i,x in enumerate(list)])

>> ['0: A', '1: B', '2: C', '3: D']
1
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
1
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?