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

python3 で、すべて小文字かどうかを判定する方法

islower() 関数を使う。 例 print(‘abcde’.islower()) print(‘abcDe’.islower()) 結果 True False

no image

python3 で切り捨て割り算(除算)

python3 で整数の割り算をして、商(の整数部)を表示するには // 演算子を使う。余りが発生した場合、商は切り捨てた整数部となる。 例 n = 201 print(str(n//2)) 結果 1 …

no image

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

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

no image

matplotlib で、凡例を表示する方法

データに label を関連付け、plt.legend() で凡例を表示する。 例 from matplotlib import pyplot as plt data_x = [25,26,2 …