{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "55db1b3f",
"metadata": {
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"# Install the necessary dependencies\n",
"\n",
"import sys\n",
"import os\n",
"!{sys.executable} -m pip install --quiet jupyterlab_myst ipython"
]
},
{
"cell_type": "markdown",
"id": "3d063176",
"metadata": {
"tags": [
"remove-cell"
]
},
"source": [
"---\n",
"license:\n",
" code: MIT\n",
" content: CC-BY-4.0\n",
"github: https://github.com/ocademy-ai/machine-learning\n",
"venue: By Ocademy\n",
"open_access: true\n",
"bibliography:\n",
" - https://raw.githubusercontent.com/ocademy-ai/machine-learning/main/open-machine-learning-jupyter-book/references.bib\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "6959d225",
"metadata": {},
"source": [
"LICENSE
\n",
"\n",
"MIT License\n",
"\n",
"Copyright (c) 2018 Oleksii Trekhleb\n",
"Copyright (c) 2018 Real Python\n",
"\n",
"Permission is hereby granted, free of charge, to any person obtaining a copy\n",
"of this software and associated documentation files (the \"Software\"), to deal\n",
"in the Software without restriction, including without limitation the rights\n",
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n",
"copies of the Software, and to permit persons to whom the Software is\n",
"furnished to do so, subject to the following conditions:\n",
"\n",
"The above copyright notice and this permission notice shall be included in all\n",
"copies or substantial portions of the Software.\n",
"\n",
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n",
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n",
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n",
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n",
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n",
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n",
"SOFTWARE.\n",
"\n",
"
Let's visualize it! 🎥
\n", "Show me the code ⌨️
\n", "\n", "\n", "```python\n", "beatles = ['John', 'Paul', 'George']\n", "beatles.append('Ringo')\n", "print(type(beatles))\n", "\n", "# 'for' loop - indentation matters!\n", "for b in beatles:\n", " print('Hello ' + b)\n", "\n", "```\n", "Let's visualize it! 🎥
\n", "Show me the code ⌨️
\n", "\n", "```python\n", "netWorth = {}\n", "netWorth['Donald Trump'] = 3000000000\n", "netWorth['Bill Gates'] = 58000000000\n", "netWorth['Tom Cruise'] = 40000000\n", "netWorth['Joe Postdoc'] = 20000\n", "print(netWorth)\n", "print(type(netWorth))\n", "\n", "# iterating over key-value pairs:\n", "\n", "for (person, worth) in netWorth.items():\n", " if worth < 1000000:\n", " print('haha ' + person + ' is not a millionaire')\n", "\n", "# testing dict membership\n", "\n", "if 'Tom Cruise' in netWorth:\n", " print('show me the money!')\n", "```\n", "\n", "Let's visualize it! 🎥
\n", "Show me the code ⌨️
\n", "\n", "```python\n", "ages = (18, 21, 28, 21, 22, 18, 19, 34, 9)\n", "\n", "uniqueAges = set(ages)\n", "uniqueAges.add(18) # already in set, no effect\n", "uniqueAges.remove(21)\n", "\n", "\n", "# no guaranteed order when iterating over a set\n", "\n", "for thisAge in uniqueAges:\n", " print(thisAge)\n", "\n", "print(type(uniqueAges))\n", "\n", "# testing set membership\n", "\n", "if 18 in uniqueAges:\n", " print('There is an 18-year-old present!')\n", "```\n", "\n", "Let's visualize it! 🎥
\n", "Show me the code ⌨️
\n", "\n", "```python\n", "x = [1, 2, 3]\n", "y = [4, 5, 6]\n", "z = y\n", "y = x\n", "x = z\n", "\n", "x = [1, 2, 3] # a different [1, 2, 3] list!\n", "y = x\n", "x.append(4)\n", "y.append(5)\n", "z = [1, 2, 3, 4, 5] # a different list!\n", "x.append(6)\n", "y.append(7)\n", "y = \"hello\"\n", "\n", "\n", "def foo(lst):\n", " lst.append(\"hello\")\n", " bar(lst)\n", "\n", "def bar(myLst):\n", " print(myLst)\n", "\n", "foo(x)\n", "foo(z)\n", "```\n", "\n", "