Skip to content

Commit

Permalink
Merge pull request #146 from gtdang/part0-nb00-suggestions
Browse files Browse the repository at this point in the history
Part0 Notebook 00 suggestions
  • Loading branch information
mnfienen authored Nov 20, 2024
2 parents 3b6122d + 3b5ec65 commit 5560ca3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
11 changes: 9 additions & 2 deletions notebooks/part0_python_intro/00_python_basics_review.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@
"keyword.kwlist"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are also built-in objects that should not be used as variable names."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -1369,7 +1376,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "pyclass",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -1383,7 +1390,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.11.10"
}
},
"nbformat": 4,
Expand Down
47 changes: 26 additions & 21 deletions notebooks/part0_python_intro/00_skills_test_on_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Read file as a list of lines\n",
"speech_raw = open(datapath / 'dream.txt').readlines() \n",
"speech = [i.strip() for i in speech_raw]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a536464e",
"metadata": {},
"outputs": [],
"source": [
"words = []\n",
"for i in speech:\n",
" words.append(i)\n",
"words"
"speech = [i.strip() for i in speech_raw] # Remove white space around each line"
]
},
{
Expand All @@ -70,8 +58,9 @@
"metadata": {},
"outputs": [],
"source": [
"words = ' '.join(words)\n",
"words"
"# join all lines as one big string\n",
"speech_string = ' '.join(speech)\n",
"speech_string"
]
},
{
Expand All @@ -82,7 +71,7 @@
"outputs": [],
"source": [
"# put this all in lower case\n",
"words = words.lower()"
"speech_string = speech_string.lower()"
]
},
{
Expand All @@ -95,18 +84,20 @@
"# get rid of punctuation using replace and replacing with empty string (e.g. '')\n",
"punks = ['.',',',':',';','!','-']\n",
"for cp in punks:\n",
" words = words.replace(cp, '')"
" speech_string = speech_string.replace(cp, '')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b755a4ce",
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# finally split on \"whitespace\" resulting in a list of words\n",
"words = words.split()\n",
"words = speech_string.split()\n",
"words"
]
},
Expand Down Expand Up @@ -292,8 +283,22 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 5560ca3

Please sign in to comment.