回答編集履歴
3
無駄を発見
answer
CHANGED
@@ -8,8 +8,8 @@
|
|
8
8
|
def window(seq, n):
|
9
9
|
cursors = tee(iter(seq), n)
|
10
10
|
|
11
|
-
for i in range(n):
|
11
|
+
for i in range(1, n):
|
12
|
-
for cursor in cursors[i
|
12
|
+
for cursor in cursors[i:]:
|
13
13
|
next(cursor, None)
|
14
14
|
|
15
15
|
return zip(*cursors)
|
2
誤字
answer
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
英語でpython sliding window で検索すると色々でてくる話ですね。
|
2
2
|
Pythonの公式ドキュメントの[itertoolsのレシピ](https://docs.python.jp/3.6/library/itertools.html#itertools-recipes)のpairwise関数も参考になります(2個の場合の正解です)。
|
3
3
|
|
4
|
-
|
4
|
+
pairwiseを2個限定からn個に拡張すると
|
5
5
|
```Python
|
6
6
|
from itertools import tee
|
7
7
|
|
1
windowsじゃなくてwindow
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
英語でpython sliding
|
1
|
+
英語でpython sliding window で検索すると色々でてくる話ですね。
|
2
2
|
Pythonの公式ドキュメントの[itertoolsのレシピ](https://docs.python.jp/3.6/library/itertools.html#itertools-recipes)のpairwise関数も参考になります(2個の場合の正解です)。
|
3
3
|
|
4
4
|
pairsiseを2個限定からn個に拡張すると
|
@@ -59,5 +59,5 @@
|
|
59
59
|
```
|
60
60
|
となります。
|
61
61
|
|
62
|
-
これはリストでなく、ファイル読み込みのようなシーケンスが対象でも十全に動きます(n行分のメモリしか使いません)。
|
62
|
+
これは、リストである必要がなく、ファイル読み込みのようなシーケンスが対象でも十全に動きます(n行分のメモリしか使いません)。
|
63
63
|
何十GBもあるようなファイルを相手にする場合の話ということで。
|