辞書に対して、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
関連記事
C言語で scanf のようなものを作るには、python では input() で実現できる。 例 print(‘xの値を入力してください’) x = input() print(‘xの値は ‘ + …
python3 で辞書(dictionary)の一部を del で削除する
辞書の一部を削除するには、del で消去したいキーを指定する。 例 dict1 = {“名前”:”太郎”, “年齢”: 20, “住所”: “東京都千代田区大手町1-1”} print(dict1) …
2023/01/18
matplotlib のグラフ作成と gnuplot との対応 比較
2022/10/14
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。