辞書に対して、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
関連記事
matplotlib の ax でx軸、y軸の端の値を設定する
axes には、set_xlim として定義する。 例 import numpy as np from matplotlib import pyplot as plt x = np.linspace( …
ヒストグラムを描くには、data_hist を使う。 ヒストグラムの縦棒の数は bins で指定する。 例 from matplotlib import pyplot as plt data_hist …
python3 でクラス内からだけアクセスするメソッドを作る方法
1.メソッド内でメソッドを定義する2.メソッド最初にアンダースコアをつける(慣習)例: def _some_internal_func(self): … このうち、2.のメソッド名先頭にアンダース …
matplotlib でグラフ表示ウィンドウの画面上の位置を自由に設定する方法
matplotlib.use(‘TkAgg’) としておき、 get_current_fig_manager().window.wm_geometry(“+20+50”) として、(+20+50)のと …
2023/01/18
matplotlib のグラフ作成と gnuplot との対応 比較
2022/10/14
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。