辞書に対して、items() メソッドを使うと、タプルを作成することができる。
例
cities = {'東京':1000,'大阪':700, '広島':100}
for a,b in cities.items():
print('a:'+a+' b:'+str(b))
結果
a:東京 b:1000 a:大阪 b:700 a:広島 b:100
雑記
投稿日:2020年12月3日 更新日:
辞書に対して、items() メソッドを使うと、タプルを作成することができる。
cities = {'東京':1000,'大阪':700, '広島':100}
for a,b in cities.items():
print('a:'+a+' b:'+str(b))
a:東京 b:1000 a:大阪 b:700 a:広島 b:100
執筆者:seyanen
関連記事
ヒストグラムを描くには、data_hist を使う。 ヒストグラムの縦棒の数は bins で指定する。 例 from matplotlib import pyplot as plt data_hist …
凡例(legend)の表示位置を変更するには、axis の legend の loc を設定する。 次のリンクhttps://matplotlib.org/stable/api/_as_gen/mat …
C言語で scanf のようなものを作るには、python では input() で実現できる。 例 print(‘xの値を入力してください’) x = input() print(‘xの値は ‘ + …
pyplot.errorbar を使って設定する。 オプションの詳細は https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.erro …
python の __str__ と __repr__ とは
python でクラスの情報を文字列で表示するとき、__str__ メソッドと __repr__ メソッドが使える。__str__ は、プログラマーとは限らないユーザーに「読める形で情報を表示」するこ …
2023/01/18
matplotlib のグラフ作成と gnuplot との対応 比較
2022/10/14
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。