回答編集履歴
5
追記
test
CHANGED
@@ -143,3 +143,17 @@
|
|
143
143
|
|
144
144
|
|
145
145
|
慣れるまではかえって読みづらいかもしれませんが。
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
---
|
150
|
+
|
151
|
+
『リストは複数形』というルールを作れば、かなり読みやすくなります。
|
152
|
+
|
153
|
+
```Python
|
154
|
+
|
155
|
+
for i, (label, feature) in enumerate(zip(labels, features)):
|
156
|
+
|
157
|
+
print(i + 1, label, feature)
|
158
|
+
|
159
|
+
```
|
4
追記
test
CHANGED
@@ -83,3 +83,63 @@
|
|
83
83
|
|
84
84
|
|
85
85
|
```
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
追記
|
90
|
+
|
91
|
+
---
|
92
|
+
|
93
|
+
せっかくなので、for文もリファクタリングしてしまいましょう。
|
94
|
+
|
95
|
+
> ```Python
|
96
|
+
|
97
|
+
> for i in range(len(feature)):
|
98
|
+
|
99
|
+
> print (str(i + 1) + " " + str(label[indices[i]]) + " " + str(feature[indices[i]])
|
100
|
+
|
101
|
+
> ```
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
まず、print関数がずいぶん冗長ですが、次のように出来ます。
|
106
|
+
|
107
|
+
```Python
|
108
|
+
|
109
|
+
for i in range(len(feature)):
|
110
|
+
|
111
|
+
print(i + 1, label[indices[i]], feature[indices[i]])
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
だいぶ横幅が狭まりましたね。
|
118
|
+
|
119
|
+
さらに、`range(len(hogehoge))`を用いている場合は、だいたい整理可能です。
|
120
|
+
|
121
|
+
```Python
|
122
|
+
|
123
|
+
for i, index in enumerate(indices):
|
124
|
+
|
125
|
+
print(i + 1, label[index], feature[index])
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
実はまだ整理できます。
|
132
|
+
|
133
|
+
`label`と`feature`を順に参照しているだけなので、まとめられます。
|
134
|
+
|
135
|
+
```Python
|
136
|
+
|
137
|
+
for i, (l, f) in enumerate(zip(label, feature)):
|
138
|
+
|
139
|
+
print(i + 1, l, f)
|
140
|
+
|
141
|
+
```
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
慣れるまではかえって読みづらいかもしれませんが。
|
3
追記
test
CHANGED
@@ -58,7 +58,7 @@
|
|
58
58
|
|
59
59
|
int main(void) {
|
60
60
|
|
61
|
-
printf("Hello World")
|
61
|
+
printf("Hello World") // ←セミコロンのつけ忘れ
|
62
62
|
|
63
63
|
return 0;
|
64
64
|
|
2
追記
test
CHANGED
@@ -43,3 +43,43 @@
|
|
43
43
|
SyntaxError: invalid syntax
|
44
44
|
|
45
45
|
```
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
文頭にシンタックスエラーが出る際は、直前の行を疑ってください。
|
50
|
+
|
51
|
+
これはどの言語にも言えることです。
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
```C
|
56
|
+
|
57
|
+
#include <stdio.h>
|
58
|
+
|
59
|
+
int main(void) {
|
60
|
+
|
61
|
+
printf("Hello World")
|
62
|
+
|
63
|
+
return 0;
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
>gcc bug.c
|
74
|
+
|
75
|
+
bug.c: In function 'main':
|
76
|
+
|
77
|
+
bug.c:4:5: error: expected ';' before 'return'
|
78
|
+
|
79
|
+
return 0;
|
80
|
+
|
81
|
+
^~~~~~
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
```
|
1
追記
test
CHANGED
@@ -21,3 +21,25 @@
|
|
21
21
|
|
22
22
|
|
23
23
|
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
---
|
28
|
+
|
29
|
+
**同様なエラーが出るコード**
|
30
|
+
|
31
|
+
```Python
|
32
|
+
|
33
|
+
>>> num = int(3
|
34
|
+
|
35
|
+
... plt = "hogehoge"
|
36
|
+
|
37
|
+
File "<stdin>", line 2
|
38
|
+
|
39
|
+
plt = "hogehoge"
|
40
|
+
|
41
|
+
^
|
42
|
+
|
43
|
+
SyntaxError: invalid syntax
|
44
|
+
|
45
|
+
```
|