Skip to content

Commit

Permalink
Light copy-edit and local run of basics NB and its completed version #81
Browse files Browse the repository at this point in the history
  • Loading branch information
zstumgoren committed Mar 6, 2024
1 parent 7afdf6b commit 4446f24
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 45 deletions.
21 changes: 14 additions & 7 deletions basics/basics_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Python Basics at PyCAR2020"
"# Python Basics"
]
},
{
Expand All @@ -26,7 +26,7 @@
"\n",
"(Most of us ask questions we've asked before daily — we just ask them of Google.)\n",
"\n",
"Now for some code. Let's say you want to search 130,000 lines of text for certain tems -- which are most common, how frequently do they occur, how often are they used in a way that's concentrated, which might indicate places you want to look more closely.\n",
"Now for some code. Let's say you want to search 130,000 lines of text for certain terms -- which are most common, how frequently do they occur, how often are they used in a way that's concentrated, which might indicate places you want to look more closely.\n",
"\n",
"No person wants to do that by hand. And people are bad at precisely that kind of work. But it's perfect for a computer.\n",
"\n",
Expand Down Expand Up @@ -97,7 +97,7 @@
"source": [
"So any time we want to check to see how many times we've seen our `search_term` or check where our `file_location` is, we can use these variables instead of typing out the card value!\n",
"\n",
"If you forget what one of the variables is set to, you can print your string. (The ```print()``` command was optional in Python 2.x, but is now required in Python 3.x.) Let's also make a comment to remind us of what this variable does."
"If you forget what one of the variables is set to, you can `print` your string. Let's also make a comment to remind us of what this variable does."
]
},
{
Expand Down Expand Up @@ -375,18 +375,25 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As you’ve just seen, programming can be pretty tedious when you’re trying to break tasks down. So now that you’ve gotten a little bit of a taste for what writing a program is like, let’s dive into some of [the nitty-gritty basics](basics_reference_completed.ipynb), like how you strip whitespace from a string and what happens when you mix a float and an integer.\n",
"As you’ve just seen, programming can be pretty tedious when you’re trying to break tasks down. So now that you’ve gotten a little bit of a taste for what writing a program is like, let’s dive into some of [the nitty-gritty basics](../completed/basics_reference_completed.ipynb), like how you strip whitespace from a string and what happens when you mix a float and an integer.\n",
"\n",
"That sounds like a lot of fun. It must. It does. We promise.\n",
"\n",
"Onward."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -400,9 +407,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
124 changes: 86 additions & 38 deletions completed/basics_complete_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Python Basics at PyCAR2020"
"# Python Basics"
]
},
{
Expand All @@ -26,7 +26,7 @@
"\n",
"(Most of us ask questions we've asked before daily — we just ask them of Google.)\n",
"\n",
"Now for some code. Let's say you want to search 130,000 lines of text for certain tems -- which are most common, how frequently do they occur, how often are they used in a way that's concentrated, which might indicate places you want to look more closely.\n",
"Now for some code. Let's say you want to search 130,000 lines of text for certain terms -- which are most common, how frequently do they occur, how often are they used in a way that's concentrated, which might indicate places you want to look more closely.\n",
"\n",
"No person wants to do that by hand. And people are bad at precisely that kind of work. But it's perfect for a computer.\n",
"\n",
Expand All @@ -52,7 +52,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -69,7 +69,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -86,7 +86,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -100,12 +100,12 @@
"source": [
"So any time we want to check to see how many times we've seen our `search_term` or check where our `file_location` is, we can use these variables instead of typing out the card value!\n",
"\n",
"If you forget what one of the variables is set to, you can print it out. (The ```print()``` command was optional in Python 2.x, but is now required in Python 3.x.) Let's also make a comment to remind us of what this variable does."
"If you forget what one of the variables is set to, you can `print` it out. Let's also make a comment to remind us of what this variable does."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -122,7 +122,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -132,7 +132,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -151,7 +151,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -168,7 +168,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -201,7 +201,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -217,7 +217,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -237,19 +237,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"achilles was in The Iliad 418 times\n"
]
}
],
"source": [
"# we can do it by adding the strings to one another like this:\n",
"print(search_term + ' was in The Iliad ' + str(term_count) + ' times')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"achilles was in The Iliad 418 times\n"
]
}
],
"source": [
"# or we can use what Python calls `f-strings`, which allow us to drop variables directly into a string;\n",
"# doing it this way means we don't have to keep track as much of wayward spaces or\n",
Expand All @@ -266,9 +282,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"It was on the same line multiple times 5 times\n",
"it was on lines [11674, 13351, 16400, 20182, 20640] multiple times\n"
]
}
],
"source": [
"print(f'It was on the same line multiple times {multi_term_line} {times}')\n",
"print(f'it was on lines {line_numbers_list} multiple times')"
Expand All @@ -290,7 +315,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -307,7 +332,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -323,7 +348,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -340,7 +365,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -357,7 +382,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -374,9 +399,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"103\n",
"37\n",
"279\n",
"28\n",
"1\n",
"215\n"
]
}
],
"source": [
"print(most_common_words[\"homer\"])\n",
"print(most_common_words['paris'])\n",
Expand All @@ -388,7 +426,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -402,9 +440,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The most common word in The Iliad is: the\n",
"It is in The Iliad 15447 times\n",
"Wow! How cool is that?\n"
]
}
],
"source": [
"print(f'The most common word in The Iliad is: {most_common_word}')\n",
"print(f'It is in The Iliad {highest_count} times')\n",
Expand All @@ -415,7 +463,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As you’ve just seen, programming can be pretty tedious when you’re trying to break tasks down. So now that you’ve gotten a little bit of a taste for what writing a program is like, let’s dive into some of [the nitty-gritty basics](basics_reference_completed.ipynb), like how you strip whitespace from a string and what happens when you mix a float and an integer.\n",
"As you’ve just seen, programming can be pretty tedious when you’re trying to break tasks down. So now that you’ve gotten a little bit of a taste for what writing a program is like, let’s dive into some of [the nitty-gritty basics](../completed/basics_reference_completed.ipynb), like how you strip whitespace from a string and what happens when you mix a float and an integer.\n",
"\n",
"That sounds like a lot of fun. It must. It does. We promise.\n",
"\n",
Expand All @@ -433,7 +481,7 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -447,9 +495,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}

0 comments on commit 4446f24

Please sign in to comment.