回答編集履歴
3
効率悪くないような気がしてきた。ジェネレータだし。
test
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
---
|
44
44
|
|
45
|
-
[collections.Counter](https://docs.python.jp/3/library/collections.html#collections.Counter)を用いた別解。
|
45
|
+
[collections.Counter](https://docs.python.jp/3/library/collections.html#collections.Counter)を用いた別解。
|
46
46
|
|
47
47
|
```Python
|
48
48
|
|
2
修正
test
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
---
|
44
44
|
|
45
|
-
[collections.Counter](https://docs.python.jp/3/library/collections.html#collections.Counter)を用いた別解。ただし効率は
|
45
|
+
[collections.Counter](https://docs.python.jp/3/library/collections.html#collections.Counter)を用いた別解。ただし効率は保証できません。
|
46
46
|
|
47
47
|
```Python
|
48
48
|
|
@@ -56,11 +56,11 @@
|
|
56
56
|
|
57
57
|
|
58
58
|
|
59
|
-
player_ans = Counter(
|
59
|
+
player_ans = Counter(
|
60
60
|
|
61
61
|
h for h, p in zip(hour, paper) for _ in range(p)
|
62
62
|
|
63
|
-
|
63
|
+
)
|
64
64
|
|
65
65
|
|
66
66
|
|
1
追記
test
CHANGED
@@ -37,3 +37,39 @@
|
|
37
37
|
2: 95
|
38
38
|
|
39
39
|
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
---
|
44
|
+
|
45
|
+
[collections.Counter](https://docs.python.jp/3/library/collections.html#collections.Counter)を用いた別解。ただし効率は良くないと思います。
|
46
|
+
|
47
|
+
```Python
|
48
|
+
|
49
|
+
from collections import Counter
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
hour = [1, 1, 1, 2, 2]
|
54
|
+
|
55
|
+
paper = [50, 50, 90, 55, 40]
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
player_ans = Counter([
|
60
|
+
|
61
|
+
h for h, p in zip(hour, paper) for _ in range(p)
|
62
|
+
|
63
|
+
])
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
for k, v in player_ans.items():
|
68
|
+
|
69
|
+
print(f'{k}: {v}')
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
[Wandbox](https://wandbox.org/permlink/qIha9CUrcaSSlwLy)
|