回答編集履歴
1
追記
test
CHANGED
@@ -29,3 +29,49 @@
|
|
29
29
|
print(s, num)
|
30
30
|
|
31
31
|
```
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
---
|
36
|
+
|
37
|
+
Pythonチュートリアルで紹介されている[OrderedCounter](https://docs.python.jp/3/library/collections.html#ordereddict-examples-and-recipes)を使う手もあります。
|
38
|
+
|
39
|
+
何度も同じような処理をするならこちらの方がより良いです。
|
40
|
+
|
41
|
+
```Python
|
42
|
+
|
43
|
+
from collections import Counter, OrderedDict
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
class OrderedCounter(Counter, OrderedDict):
|
48
|
+
|
49
|
+
'Counter that remembers the order elements are first encountered'
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
def __repr__(self):
|
54
|
+
|
55
|
+
return '%s(%r)' % (self.__class__.__name__, OrderedDict(self))
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
def __reduce__(self):
|
60
|
+
|
61
|
+
return self.__class__, (OrderedDict(self),)
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
data = input().split()
|
66
|
+
|
67
|
+
a = OrderedCounter(data)
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
for s, num in a.items():
|
72
|
+
|
73
|
+
print(s, num)
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
```
|