回答編集履歴

2

Counter()

2018/09/18 00:27

投稿

opyon
opyon

スコア1009

test CHANGED
@@ -46,6 +46,20 @@
46
46
 
47
47
  ```
48
48
 
49
+
50
+
51
+ @tachikomaさんに教えていただいたCounter()で実装も参考までに追記。
52
+
53
+ ```Python3
54
+
55
+ from collections import Counter
56
+
57
+ for country,value in Counter(src).items():
58
+
59
+ print("{}:{}".format(country,value))
60
+
61
+ ```
62
+
49
63
  出力結果
50
64
 
51
65
  イギリス:7

1

簡潔に

2018/09/18 00:27

投稿

opyon
opyon

スコア1009

test CHANGED
@@ -32,6 +32,20 @@
32
32
 
33
33
  ```
34
34
 
35
+
36
+
37
+ さらに出力と処理を同時に出来ます。
38
+
39
+ ```Python3
40
+
41
+ country_set = set(src)
42
+
43
+ for country in country_set:
44
+
45
+ print("{}:{}".format(country,src.count(country)))
46
+
47
+ ```
48
+
35
49
  出力結果
36
50
 
37
51
  イギリス:7