Skip to content

Commit 52c9170

Browse files
committed
Refactor for-else example
1 parent 6b0688e commit 52c9170

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

notebooks/intermediate/idiomatic_loops.ipynb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,9 @@
332332
"source": [
333333
"found = False\n",
334334
"for val in data:\n",
335-
" if isinstance(val, str):\n",
336-
" if val.lower() == 'python':\n",
337-
" found = True\n",
338-
" break\n",
335+
" if str(val).lower() == 'python':\n",
336+
" found = True\n",
337+
" break\n",
339338
"if not found:\n",
340339
" raise ValueError(\"Nope, couldn't find.\")"
341340
]
@@ -354,9 +353,8 @@
354353
"outputs": [],
355354
"source": [
356355
"for val in data:\n",
357-
" if isinstance(val, str):\n",
358-
" if val.lower() == 'python':\n",
359-
" break\n",
356+
" if str(val).lower() == 'python':\n",
357+
" break\n",
360358
"else:\n",
361359
" raise ValueError(\"Nope, couldn't find.\")"
362360
]

0 commit comments

Comments
 (0)