回答編集履歴

2

2022/10/13 08:08

投稿

melian
melian

スコア19618

test CHANGED
@@ -16,5 +16,5 @@
16
16
 
17
17
  '''.strip()
18
18
 
19
- print(re.sub(r'\n+', '\n', text))
19
+ print(re.sub(r'\n{2,}', '\n', text))
20
20
  ```

1

2022/10/13 07:40

投稿

melian
melian

スコア19618

test CHANGED
@@ -1,15 +1,20 @@
1
1
  ```python
2
+ import re
3
+
2
4
  text = '''
3
5
 
4
6
  ・AAA
5
7
  ・BBB
6
8
  ・CCC
7
9
 
10
+
8
11
  ・DDD
12
+
13
+
9
14
 
10
15
  ・EEE
11
16
 
12
17
  '''.strip()
13
18
 
14
- print(text.replace('\n\n', '\n'))
19
+ print(re.sub(r'\n+', '\n', text))
15
20
  ```