回答編集履歴

2

もっと単純でいけた

2019/01/12 05:51

投稿

YouheiSakurai
YouheiSakurai

スコア6142

test CHANGED
@@ -10,8 +10,8 @@
10
10
 
11
11
  print(i)
12
12
 
13
- if i == 3 and next(iterable, None) is None:
13
+ if i == 3:
14
14
 
15
- break
15
+ next(iterable, None)
16
16
 
17
17
  ```

1

汎用的を消す&もうちょっと読みやすく

2019/01/12 05:51

投稿

YouheiSakurai
YouheiSakurai

スコア6142

test CHANGED
@@ -1,36 +1,4 @@
1
- **汎用的にN個先を飛ばしたいなら**
2
-
3
-
4
-
5
- ```python
6
-
7
- from functools import partial
8
-
9
- from itertools import filterfalse
10
-
11
- from operator import contains
12
-
13
-
14
-
15
- N = 1
16
-
17
- skip = set()
18
-
19
- skip_in = partial(contains, skip)
20
-
21
- for i in filterfalse(skip_in, range(1, 11)):
22
-
23
- print(i)
24
-
25
- if i == 3:
26
-
27
- skip.add(i + N)
28
-
29
- ```
30
-
31
-
32
-
33
- **ただ単純に1個先を飛ばしたいなら**
1
+ **ただ単純に1個先を飛ば**
34
2
 
35
3
 
36
4
 
@@ -42,7 +10,7 @@
42
10
 
43
11
  print(i)
44
12
 
45
- if i == 3 and not next(iterable, None):
13
+ if i == 3 and next(iterable, None) is None:
46
14
 
47
15
  break
48
16