回答編集履歴

5

大幅に変更しました

2017/11/04 04:22

投稿

_Victorique__
_Victorique__

スコア1392

test CHANGED
@@ -1,23 +1,19 @@
1
1
  ```Python
2
2
 
3
- lst = [1,2,3,4,5,1,2,3,4,1,2,1,2,3,4,5,6]
3
+ lst = [1,2,3,4,5,1,2,3,4,1,2,1,2,3,4,5,6]+[1]
4
4
 
5
- lst = map(str, lst)
5
+ num = [i for i,n in enumerate(lst+[1]) if n==1 or lst[i+1]==1]
6
6
 
7
- s = "".join(lst)
7
+ num_lst = [num[i:i+2] for i in range(0,len(num),2)]
8
8
 
9
- s_lst = s.split('1')
9
+ ans = [lst[sf[0]:sf[1]+1] for i,sf in enumerate(num_lst) if i!=len(num_lst)-1]
10
10
 
11
- s_lst = [s for s in s_lst if s!='']
12
-
13
- s_lst = list(map(lambda x: [int('1'+x)], s_lst))
14
-
15
- print(s_lst)
11
+ print(ans)
16
12
 
17
13
 
18
14
 
19
15
  出力結果
20
16
 
21
- [[12345], [1234], [12], [123456]]
17
+ [[1, 2, 3, 4, 5], [1, 2, 3, 4], [1, 2], [1, 2, 3, 4, 5, 6]]
22
18
 
23
19
  ```

4

編集

2017/11/04 04:22

投稿

_Victorique__
_Victorique__

スコア1392

test CHANGED
@@ -18,6 +18,6 @@
18
18
 
19
19
  出力結果
20
20
 
21
- [12345, 1234, 12, 123456]
21
+ [[12345], [1234], [12], [123456]]
22
22
 
23
23
  ```

3

編集

2017/11/04 03:41

投稿

_Victorique__
_Victorique__

スコア1392

test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  s_lst = [s for s in s_lst if s!='']
12
12
 
13
- s_lst = list(map(lambda x: int('1'+x), s_lst))
13
+ s_lst = list(map(lambda x: [int('1'+x)], s_lst))
14
14
 
15
15
  print(s_lst)
16
16
 

2

編集

2017/11/04 03:40

投稿

_Victorique__
_Victorique__

スコア1392

test CHANGED
@@ -18,6 +18,6 @@
18
18
 
19
19
  出力結果
20
20
 
21
- [1, 12345, 1234, 12, 123456]
21
+ [12345, 1234, 12, 123456]
22
22
 
23
23
  ```

1

コードを修正しました

2017/11/04 03:35

投稿

_Victorique__
_Victorique__

スコア1392

test CHANGED
@@ -7,6 +7,8 @@
7
7
  s = "".join(lst)
8
8
 
9
9
  s_lst = s.split('1')
10
+
11
+ s_lst = [s for s in s_lst if s!='']
10
12
 
11
13
  s_lst = list(map(lambda x: int('1'+x), s_lst))
12
14