diff --git a/01 - The Basics/02 - Flow Control.ipynb b/01 - The Basics/02 - Flow Control.ipynb index bda4137..c91a927 100644 --- a/01 - The Basics/02 - Flow Control.ipynb +++ b/01 - The Basics/02 - Flow Control.ipynb @@ -442,6 +442,47 @@ "On the next loop around the `while` keyword sees that `keep_going` is no longer `True` and so we `break` out of the loop and can move on to the next piece of code." ] }, + { + "cell_type": "markdown", + "id": "ae0250b5", + "metadata": {}, + "source": [ + "## `match` statements\n", + "\n", + "What if we performantly want to check a variable against multiple possible values?\n", + "\n", + "In other languages such flow control is called a `switch` statement, in Python it's called `match`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "66c29c8c", + "metadata": {}, + "outputs": [], + "source": [ + "import datetime\n", + "today = datetime.date.today()\n", + "\n", + "match today.weekday():\n", + " case 0:\n", + " print(\"Today is Sunday\")\n", + " case 1:\n", + " print(\"Today is Monday\")\n", + " case 2:\n", + " print(\"Today is Tuesday\")\n", + " case 3:\n", + " print(\"Today is Wednesday\")\n", + " case 4:\n", + " print(\"Today is Thursday\")\n", + " case 5:\n", + " print(\"Today is Friday\")\n", + " case 6:\n", + " print(\"Today is Saturday\")\n", + " case _:\n", + " print(\"Today is a day I don't know\")" + ] + }, { "cell_type": "markdown", "id": "1fb9627b", @@ -455,7 +496,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "dev", "language": "python", "name": "python3" }, @@ -469,7 +510,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.5" + "version": "3.12.2" } }, "nbformat": 4, diff --git a/02 - Data Handling/01 - Data Ingest.ipynb b/02 - Data Handling/01 - Data Ingest.ipynb index c48a509..4ceec66 100644 --- a/02 - Data Handling/01 - Data Ingest.ipynb +++ b/02 - Data Handling/01 - Data Ingest.ipynb @@ -21,11 +21,11 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install h5py\n", - "!pip install numpy\n", - "!pip install matplotlib\n", + "%pip install h5py\n", + "%pip install numpy\n", + "%pip install matplotlib\n", "\n", - "!git clone https://github.com/timsnow/advanced_sas_training_course\n", + "%git clone https://github.com/timsnow/advanced_sas_training_course\n", "%cd 'advanced_sas_training_course/02 - Data Handling'" ] }, @@ -51,7 +51,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "6d95abee", "metadata": {}, "outputs": [], @@ -635,7 +635,7 @@ "\n", "The beginner's cheatsheet is probably enough to be going on for now:\n", "\n", - "![Beginner's cheatsheet](https://github.com/matplotlib/cheatsheets/raw/master/handout-beginner.png)\n", + "![Beginner's cheatsheet](https://camo.githubusercontent.com/39835016ed0289de8d01ba786509de814caba7bf193c017e245a87a1bd9d70b7/68747470733a2f2f6d6174706c6f746c69622e6f72672f63686561747368656574732f68616e646f75742d626567696e6e65722e706e67)\n", "\n", "\n", "With all of this in mind - we can finally arrive at a graph like this:" @@ -733,7 +733,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "dev", "language": "python", "name": "python3" }, @@ -747,7 +747,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.5" + "version": "3.12.2" } }, "nbformat": 4, diff --git a/02 - Data Handling/02 - Function Fitting with lmfit.ipynb b/02 - Data Handling/02 - Function Fitting with lmfit.ipynb index 901aacd..e0c32f1 100644 --- a/02 - Data Handling/02 - Function Fitting with lmfit.ipynb +++ b/02 - Data Handling/02 - Function Fitting with lmfit.ipynb @@ -28,12 +28,12 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install h5py\n", - "!pip install lmfit\n", - "!pip install numpy\n", - "!pip install matplotlib\n", + "%pip install h5py\n", + "%pip install lmfit\n", + "%pip install numpy\n", + "%pip install matplotlib\n", "\n", - "!git clone https://github.com/timsnow/advanced_sas_training_course\n", + "%git clone https://github.com/timsnow/advanced_sas_training_course\n", "%cd 'advanced_sas_training_course/02 - Data Handling'" ] }, @@ -583,7 +583,7 @@ "metadata": {}, "outputs": [], "source": [ - "numpy.savetxt(file_path, array, delimiter='\\t', newline='\\n', header='', footer='', comments='# ')" + "np.savetxt(file_path, array, delimiter='\\t', newline='\\n', header='', footer='', comments='# ')" ] }, { diff --git a/02 - Data Handling/03 - Exercises.ipynb b/02 - Data Handling/03 - Exercises.ipynb index e8a0106..ef15828 100644 --- a/02 - Data Handling/03 - Exercises.ipynb +++ b/02 - Data Handling/03 - Exercises.ipynb @@ -23,12 +23,12 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install h5py\n", - "!pip install lmfit\n", - "!pip install numpy\n", - "!pip install matplotlib\n", + "%pip install h5py\n", + "%pip install lmfit\n", + "%pip install numpy\n", + "%pip install matplotlib\n", "\n", - "!git clone https://github.com/timsnow/advanced_sas_training_course\n", + "%git clone https://github.com/timsnow/advanced_sas_training_course\n", "%cd 'advanced_sas_training_course/02 - Data Handling'" ] }, diff --git a/02 - Data Handling/04 - Exercises and Answers.ipynb b/02 - Data Handling/04 - Exercises and Answers.ipynb index cacbcbb..10ff6ea 100644 --- a/02 - Data Handling/04 - Exercises and Answers.ipynb +++ b/02 - Data Handling/04 - Exercises and Answers.ipynb @@ -23,12 +23,12 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install h5py\n", - "!pip install lmfit\n", - "!pip install numpy\n", - "!pip install matplotlib\n", + "%pip install h5py\n", + "%pip install lmfit\n", + "%pip install numpy\n", + "%pip install matplotlib\n", "\n", - "!git clone https://github.com/timsnow/advanced_sas_training_course\n", + "%git clone https://github.com/timsnow/advanced_sas_training_course\n", "%cd 'advanced_sas_training_course/02 - Data Handling'" ] }, diff --git a/03 - SAS Software/01 - SasView.ipynb b/03 - SAS Software/01 - SasView.ipynb index b36b1b4..a2fb852 100644 --- a/03 - SAS Software/01 - SasView.ipynb +++ b/03 - SAS Software/01 - SasView.ipynb @@ -17,12 +17,12 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install bumps\n", - "!pip install numpy\n", - "!pip install sasmodels\n", - "!pip install matplotlib\n", + "%pip install bumps\n", + "%pip install numpy\n", + "%pip install sasmodels\n", + "%pip install matplotlib\n", "\n", - "!git clone https://github.com/timsnow/advanced_sas_training_course\n", + "%git clone https://github.com/timsnow/advanced_sas_training_course\n", "%cd 'advanced_sas_training_course/03 - SAS Software'" ] }, diff --git a/03 - SAS Software/02 - Exercises.ipynb b/03 - SAS Software/02 - Exercises.ipynb index 8414540..62d2f5f 100644 --- a/03 - SAS Software/02 - Exercises.ipynb +++ b/03 - SAS Software/02 - Exercises.ipynb @@ -17,12 +17,12 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install bumps\n", - "!pip install numpy\n", - "!pip install sasmodels\n", - "!pip install matplotlib\n", + "%pip install bumps\n", + "%pip install numpy\n", + "%pip install sasmodels\n", + "%pip install matplotlib\n", "\n", - "!git clone https://github.com/timsnow/advanced_sas_training_course\n", + "%git clone https://github.com/timsnow/advanced_sas_training_course\n", "%cd 'advanced_sas_training_course/03 - SAS Software'" ] }, diff --git a/03 - SAS Software/03 - Exercises and Answers.ipynb b/03 - SAS Software/03 - Exercises and Answers.ipynb index fa5b5e8..bb5f13d 100644 --- a/03 - SAS Software/03 - Exercises and Answers.ipynb +++ b/03 - SAS Software/03 - Exercises and Answers.ipynb @@ -17,12 +17,12 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install bumps\n", - "!pip install numpy\n", - "!pip install sasmodels\n", - "!pip install matplotlib\n", + "%pip install bumps\n", + "%pip install numpy\n", + "%pip install sasmodels\n", + "%pip install matplotlib\n", "\n", - "!git clone https://github.com/timsnow/advanced_sas_training_course\n", + "%git clone https://github.com/timsnow/advanced_sas_training_course\n", "%cd 'advanced_sas_training_course/03 - SAS Software'" ] },