回答編集履歴
1
マジックナンバーの消去
answer
CHANGED
@@ -2,19 +2,21 @@
|
|
2
2
|
|
3
3
|
```python
|
4
4
|
class Aggregate(dict):
|
5
|
-
def __init__(self):
|
5
|
+
def __init__(self, maxcount=100, endcode='9999'):
|
6
6
|
self.count = 0
|
7
|
+
self.maxcount = maxcount
|
8
|
+
self.endcode = endcode
|
7
9
|
|
8
10
|
def entry(self, s):
|
9
11
|
code, sales = s.split()
|
10
|
-
if code ==
|
12
|
+
if code == self.maxcount:
|
11
13
|
return False
|
12
14
|
if code in self:
|
13
15
|
self[code] += int(sales)
|
14
16
|
else:
|
15
17
|
self[code] = int(sales)
|
16
18
|
self.count += 1
|
17
|
-
return self.count <
|
19
|
+
return self.count < self.maxcount
|
18
20
|
|
19
21
|
def __repr__(self):
|
20
22
|
return '\n'.join([f'{key} {self[key]}' for key in self])
|