質問編集履歴

2

うまくいったコードを追記しました

2019/11/09 08:10

投稿

Koshikake
Koshikake

スコア6

test CHANGED
File without changes
test CHANGED
@@ -74,6 +74,26 @@
74
74
 
75
75
  ```
76
76
 
77
+ 更新しました。このコードでうまくいきました。
78
+
79
+ ```
80
+
81
+ a=['1apple\n', '23banana\n', '34cherry\n', '4567dragonfruits\n']
82
+
83
+ import re
84
+
85
+ for i in a:
86
+
87
+ b=re.sub(r"\d","",i)
88
+
89
+ c=re.sub(r"\n","",b)
90
+
91
+ print(c)
92
+
93
+
94
+
95
+ ```
96
+
77
97
 
78
98
 
79
99
 

1

エラーメッセージの更新、ソースコードの更新を行いました

2019/11/09 08:10

投稿

Koshikake
Koshikake

スコア6

test CHANGED
File without changes
test CHANGED
@@ -28,6 +28,20 @@
28
28
 
29
29
 
30
30
 
31
+ 更新しました
32
+
33
+ Traceback (most recent call last):
34
+
35
+ File "XXXX.py", line 4, in <module>
36
+
37
+ list_b[i]=re.sub(r"\d","",list_a[i])
38
+
39
+ TypeError: list indices must be integers or slices, not str
40
+
41
+
42
+
43
+
44
+
31
45
  ### 該当のソースコード
32
46
 
33
47
  list_a=['1apple\n', '23banana\n', '34cherry\n', '4567dragonfruits\n']
@@ -41,6 +55,28 @@
41
55
  list_c[i]=re.sub(r"\n","",list_b[i])
42
56
 
43
57
    print(c)
58
+
59
+
60
+
61
+ 更新しました
62
+
63
+ ```list_a=['1apple\n', '23banana\n', '34cherry\n', '4567dragonfruits\n']
64
+
65
+ import re
66
+
67
+ for i in list_a:
68
+
69
+ list_b[i]=re.sub(r"\d","",list_a[i])
70
+
71
+ list_c[i]=re.sub(r"\n","",list_b[i])
72
+
73
+ print(c)
74
+
75
+ ```
76
+
77
+
78
+
79
+
44
80
 
45
81
 
46
82