0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

辞書データの順序

Posted at

最初、辞書から辞書のデータを表示できるかと思ってたら
なかなかできなかったのでメモ。
下記のようにしたらできるように。
1つの辞書だけで動かそうと思うんではなく、
別のリストから操作できるようにすることもできるということを学びました。

n = int(input())
Data = {}
for _ in range(n):
    [a,b] = input(),0
    Data[a] = b

m = int (input())

for _ in range(m):
    [a,b] = input().split()
    Data[a] += int(b)

#ここからnameだけのリストを別に作る
names = list(Data.keys())
names.sort()

#そのリストに合わせて値を表示させる
for name in names:
    print(Data[name])
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?