python3

python3 の辞書で、キー一覧を取り出して表示する方法

投稿日:2020年12月20日 更新日:

keys()メソッドでは、キー一覧を取得できる。

values() では、値を取得できる。

items() では、キーと値をタプルとして取得できる。

リストに変換すると、print() でコンソールに表示できる。

mydict = {'a':1,'b':2,'c':123}

print(list(mydict.keys()))
print(list(mydict.values()))
print(list(mydict.items()))

結果

['a', 'b', 'c']
[1, 2, 123]
[('a', 1), ('b', 2), ('c', 123)]
[商品価格に関しましては、リンクが作成された時点と現時点で情報が変更されている場合がございます。]

黒子のバスケ カラー版 1【電子書籍】[ 藤巻忠俊 ]
価格:528円(税別、送料別)(2020/12/24時点)

楽天で購入

-python3
-

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

matplotlib で、凡例を表示する位置を変更する方法

凡例(legend)の表示位置を変更するには、axis の legend の loc を設定する。 次のリンクhttps://matplotlib.org/stable/api/_as_gen/mat …

no image

matplotlib で、グラフの線の幅を変更する方法

lw で、線幅を数字で指定すればよい。 例 from matplotlib import pyplot as plt data_x = [25,26,27] data_y = [39, …

no image

python3 で整数の割り算、商と余りを求める方法

floor divisionを使う。 例 a = 15 // 7 b = 15 % 7 print(a) print(b) 結果 2 1

no image

matplotlib で、ヒストグラムを作成する方法

ヒストグラムを描くには、data_hist を使う。 ヒストグラムの縦棒の数は bins で指定する。 例 from matplotlib import pyplot as plt data_hist …

no image

python3 で、リストを pop したものの返り値

リストを pop すると、 pop された値が返される。 例 plant_1 = [’pumpkin’, ‘ginger’, ‘potato’] plant_2 = [] print( …