回答編集履歴
4
追記
test
CHANGED
@@ -116,6 +116,46 @@
|
|
116
116
|
|
117
117
|
dst[-1].append(i)
|
118
118
|
|
119
|
-
|
119
|
+
```
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
さらに追記
|
124
|
+
|
125
|
+
---
|
126
|
+
|
127
|
+
普通に読み辛いですし効率面も特段良くありませんが、個人的にはこういうのが好きです。
|
128
|
+
|
129
|
+
おまけです。
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
```Python
|
134
|
+
|
135
|
+
indice_1 = (
|
136
|
+
|
137
|
+
i for i, e in enumerate(src)
|
138
|
+
|
139
|
+
if e == 1
|
140
|
+
|
141
|
+
)
|
142
|
+
|
143
|
+
dst = [
|
144
|
+
|
145
|
+
[idx, *map(operator.itemgetter(0), zip(
|
146
|
+
|
147
|
+
itertools.count(idx+1),
|
148
|
+
|
149
|
+
itertools.takewhile(
|
150
|
+
|
151
|
+
lambda e: e == 2, src[idx+1:]
|
152
|
+
|
153
|
+
)
|
154
|
+
|
155
|
+
))]
|
156
|
+
|
157
|
+
for idx in indice_1
|
158
|
+
|
159
|
+
]
|
120
160
|
|
121
161
|
```
|
3
追記
test
CHANGED
@@ -79,3 +79,43 @@
|
|
79
79
|
i += 1
|
80
80
|
|
81
81
|
```
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
for文を使うなら二回に分けた方が無駄が少ないように思います。
|
86
|
+
|
87
|
+
```Python
|
88
|
+
|
89
|
+
dst = []
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
it = (
|
94
|
+
|
95
|
+
i for i, e in enumerate(src)
|
96
|
+
|
97
|
+
if e == 1
|
98
|
+
|
99
|
+
)
|
100
|
+
|
101
|
+
for index_1 in it:
|
102
|
+
|
103
|
+
dst.append([index_1])
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
idx = index_1 + 1
|
108
|
+
|
109
|
+
for i, e in enumerate(src[idx:], start=idx):
|
110
|
+
|
111
|
+
if e != 2:
|
112
|
+
|
113
|
+
break
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
dst[-1].append(i)
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
```
|
2
追記
test
CHANGED
@@ -39,3 +39,43 @@
|
|
39
39
|
[[6], [9, 10, 11]]
|
40
40
|
|
41
41
|
```
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
コメントを受けて
|
46
|
+
|
47
|
+
---
|
48
|
+
|
49
|
+
例えば、こんなふうに。
|
50
|
+
|
51
|
+
```Python
|
52
|
+
|
53
|
+
dst = []
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
i = 0
|
58
|
+
|
59
|
+
while i < len(src):
|
60
|
+
|
61
|
+
if src[i] != 1:
|
62
|
+
|
63
|
+
i += 1
|
64
|
+
|
65
|
+
continue
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
dst.append([i])
|
70
|
+
|
71
|
+
i += 1
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
while i < len(src) and src[i] == 2:
|
76
|
+
|
77
|
+
dst[-1].append(i)
|
78
|
+
|
79
|
+
i += 1
|
80
|
+
|
81
|
+
```
|
1
追記
test
CHANGED
@@ -8,7 +8,11 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
src = [4,
|
11
|
+
src = [4,4,2,4,5,3,1,3,4,1,2,2,3]
|
12
|
+
|
13
|
+
assert all(len(str(e)) == 1 for e in src) # srcの全要素は1桁
|
14
|
+
|
15
|
+
|
12
16
|
|
13
17
|
dst = [
|
14
18
|
|
@@ -28,14 +32,10 @@
|
|
28
32
|
|
29
33
|
|
30
34
|
|
31
|
-
**実行結果** [Wandbox](https://wandbox.org/permlink/
|
35
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/SVnsvzydmFuJXlyh)
|
32
36
|
|
33
37
|
```
|
34
38
|
|
35
39
|
[[6], [9, 10, 11]]
|
36
40
|
|
37
41
|
```
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
srcの全ての要素が1桁の整数との前提です。
|