|
204 | 204 | "# for the c programmer, there is no for (i = 0, i < n, i++) equivalent\n", |
205 | 205 | "my_list_result = []\n", |
206 | 206 | "for i in range(0, len(my_list_todos)):\n", |
207 | | - " if my_list_todos[i] == \"add\":\n", |
| 207 | + " if my_list_todos[i] is \"add\":\n", |
208 | 208 | " my_list_result.append(my_list_lhs_numbers[i] + my_list_rhs_numbers[i])\n", |
209 | | - " elif my_list_todos[i] == \"multiply\":\n", |
| 209 | + " elif my_list_todos[i] is \"multiply\":\n", |
210 | 210 | " my_list_result.append(my_list_lhs_numbers[i] * my_list_rhs_numbers[i])\n", |
211 | | - " elif my_list_todos[i] == \"skip\":\n", |
| 211 | + " elif my_list_todos[i] is \"skip\":\n", |
212 | 212 | " pass \n", |
213 | 213 | " else:\n", |
214 | 214 | " # This is the RIGHT way to do this, so you catch if someone mis-typed something\n", |
|
244 | 244 | "\n", |
245 | 245 | "# Notice i, n\n", |
246 | 246 | "for i, n in enumerate(my_list_todos):\n", |
247 | | - " if n == \"add\":\n", |
| 247 | + " if n is \"add\":\n", |
248 | 248 | " my_list_result.append(my_list_lhs_numbers[i] + my_list_rhs_numbers[i])\n", |
249 | | - " elif n == \"multiply\":\n", |
| 249 | + " elif n is \"multiply\":\n", |
250 | 250 | " my_list_result.append(my_list_lhs_numbers[i] * my_list_rhs_numbers[i])\n", |
251 | | - " elif n == \"skip\":\n", |
| 251 | + " elif n is \"skip\":\n", |
252 | 252 | " pass # This is the RIGHT way to do this, so you catch if someone mis-typed something\n", |
253 | 253 | " else:\n", |
254 | 254 | " raise ValueError(f\"Expected add, multiply, or skip, got {n}\")\n", |
|
266 | 266 | "# Note also that this does NOT require an index variable i - it's all handled for you\n", |
267 | 267 | "my_list_result = [] # Set list back to empty\n", |
268 | 268 | "for n, lhs, rhs in zip(my_list_todos, my_list_lhs_numbers, my_list_rhs_numbers):\n", |
269 | | - " if n == \"add\":\n", |
| 269 | + " if n is \"add\":\n", |
270 | 270 | " my_list_result.append(lhs + rhs)\n", |
271 | | - " elif n == \"multiply\":\n", |
| 271 | + " elif n is \"multiply\":\n", |
272 | 272 | " my_list_result.append(lhs * rhs)\n", |
273 | | - " elif n == \"skip\":\n", |
| 273 | + " elif n is \"skip\":\n", |
274 | 274 | " pass \n", |
275 | 275 | " else:\n", |
276 | 276 | " # This is the RIGHT way to do this, so you catch if someone mis-typed something\n", |
|
0 commit comments