回答編集履歴
4
作文の修正
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
この手の問題を強引に解決する
|
1
|
+
この手の問題を強引に解決するのは多少面倒で、正規表現の利用が検討されます。
|
2
2
|
```Python
|
3
3
|
import re
|
4
4
|
|
3
作文の修正
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
こ
|
1
|
+
この手の問題を強引に解決するには多少面倒で、正規表現の利用が検討されます。
|
2
2
|
```Python
|
3
3
|
import re
|
4
4
|
|
2
追記
answer
CHANGED
@@ -18,9 +18,10 @@
|
|
18
18
|
|
19
19
|
これを機に少し学んでみては。
|
20
20
|
|
21
|
-
|
21
|
+
あるいは
|
22
22
|
---
|
23
|
-
自由度が低くても良ければ、str.startswith
|
23
|
+
自由度が低くても良ければ、str.startswithを利用するのもアリです。
|
24
|
+
ただし、ちょっとでも問題が複雑になると対処できなくなります。
|
24
25
|
```Python
|
25
26
|
with open('text.txt') as fin:
|
26
27
|
data = fin.read()
|
@@ -32,4 +33,10 @@
|
|
32
33
|
print(
|
33
34
|
line[len('my name is '):]
|
34
35
|
)
|
36
|
+
```
|
37
|
+
|
38
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/JaEcne7mVedNCoAl)
|
39
|
+
```plain
|
40
|
+
[familyname]power, [givenname]point
|
41
|
+
[familyname]!!!, [givenname]????
|
35
42
|
```
|
1
追記
answer
CHANGED
@@ -16,4 +16,20 @@
|
|
16
16
|
[familyname]!!!, [givenname]????
|
17
17
|
```
|
18
18
|
|
19
|
-
これを機に少し学んでみては。
|
19
|
+
これを機に少し学んでみては。
|
20
|
+
|
21
|
+
ただし
|
22
|
+
---
|
23
|
+
自由度が低くても良ければ、str.startswithの利用もご検討ください。
|
24
|
+
```Python
|
25
|
+
with open('text.txt') as fin:
|
26
|
+
data = fin.read()
|
27
|
+
|
28
|
+
for line in data.split('\n'):
|
29
|
+
if not line.startswith('my name is '):
|
30
|
+
continue
|
31
|
+
|
32
|
+
print(
|
33
|
+
line[len('my name is '):]
|
34
|
+
)
|
35
|
+
```
|