Skip to content

s5 final #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 01-Fundamentals.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ In [Intro to Python](https://hutchdatascience.org/Intro_to_Python/), you learned
We will be looking at a dataset from Twitter that looks like the following:

| Tweet_ID | Username | Text | Retweets | Likes | Timestamp |
|------------|------------|------------|------------|------------|------------|
|----------|----------------|-------------------------------------------|----------|-------|---------------------|
| 1 | julie81 | Party least receive say or single.... | 2 | 25 | 2023-01-30 11:00:51 |
| 2 | richardhester | Hotel still Congress may member staff.... | 35 | 29 | 2023-01-02 22:45:58 |
| 3 | williamsjoseph | Nice be her debate industry that year.... | 51 | 25 | 2023-01-18 11:25:19 |
Expand Down
2 changes: 1 addition & 1 deletion 02-Iteration.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ for key, value in sentiment.items():

**Ranges** are a collection of sequential numbers, such as:

- 1, 2, 3, 4, 5
- 1, 2, 3, 4, 5

- 1, 3, 5

Expand Down
2 changes: 1 addition & 1 deletion 03-Conditionals.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Let's see this in action step by step:

</iframe>

If it doesn't load properly, you can find it [here](https://pythontutor.com/render.html#code=heartrates%20%3D%20%5B68,%2054,%2072,%2066,%2090,%20102%5D%0A%0Afor%20index,%20rate%20in%20enumerate%28heartrates%29%3A%0A%20%20if%20rate%20%3E%200%20and%20rate%20%3C%3D%2060%3A%0A%20%20%20%20heartrates%5Bindex%5D%20%3D%20%22low%22%0A%20%20elif%20rate%20%3E%2060%20and%20rate%20%3C%3D%20100%3A%0A%20%20%20%20heartrates%5Bindex%5D%20%3D%20%22medium%22%0A%20%20elif%20rate%20%3E%20100%3A%0A%20%20%20%20heartrates%5Bindex%5D%20%3D%20%22high%22%0A%20%20else%3A%0A%20%20%20%20heartrates%5Bindex%5D%20%3D%20%22unknown%22%0A%20%20%20%20%0Aprint%28heartrates%29&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false)
If it doesn't load properly, you can find it [here](https://pythontutor.com/render.html#code=heartrates%20%3D%20%5B68,%2054,%2072,%2066,%2090,%20102%5D%0A%0Afor%20index,%20rate%20in%20enumerate%28heartrates%29%3A%0A%20%20if%20rate%20%3E%200%20and%20rate%20%3C%3D%2060%3A%0A%20%20%20%20heartrates%5Bindex%5D%20%3D%20%22low%22%0A%20%20elif%20rate%20%3E%2060%20and%20rate%20%3C%3D%20100%3A%0A%20%20%20%20heartrates%5Bindex%5D%20%3D%20%22medium%22%0A%20%20elif%20rate%20%3E%20100%3A%0A%20%20%20%20heartrates%5Bindex%5D%20%3D%20%22high%22%0A%20%20else%3A%0A%20%20%20%20heartrates%5Bindex%5D%20%3D%20%22unknown%22%0A%20%20%20%20%0Aprint%28heartrates%29&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false).

## Exercises

Expand Down
8 changes: 3 additions & 5 deletions 04-Functions.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

After learning how to use other people's functions, it's time to write our own! We will look at the anatomy of how a function is constructed, and see bunch of examples in action.

![Source: <https://moffett4understandingmath.com/wp-content/uploads/2017/06/function-machine.png>](https://moffett4understandingmath.com/wp-content/uploads/2017/06/function-machine.png){width="300"}

First, we remind ourselves why we write functions in the first place. We write functions for two main, often overlapping, reasons:

1. Following DRY (Don't Repeat Yourself) principle: If you find yourself repeating similar patterns of code, you should write a function that executes that pattern. This saves time and the risk of mistakes.
Expand Down Expand Up @@ -60,9 +58,9 @@ We need to introduce the concept of local and global environments to distinguish

Within a function, all input arguments and any new variables defined are stored in a "**local environment**", and is only accessible within the function's body. The overall environment of the program is called the "**global environment**" and can be also accessed within the function.

The reason of having some of this "privacy" in the local environment is to make functions modular - they are independent little tools that should not interact with the rest of the global environment. Imagine someone writing a tool that they want to give someone else to use, but the tool depends on your environment, vice versa.
The reason of having some of this "privacy" in the local environment is to make functions modular - they are independent little tools that should not interact with the rest of the global environment. Imagine you writing a function that you want to give someone else to use, but your function depends on your global environment - it would not be portable!

To illustrate the distinguish between a the local and global environment, the following tool allows you to step through Python code execution line-by-line and see the relationship between order of execution, variables, and environments. The "Global frame" refers to the global environment, and "add_numbers" refer to the local environment for the function `add_numbers()`.
To illustrate the distinction between a the local and global environment, the following tool allows you to step through Python code execution line-by-line and see the relationship between order of execution, variables, and environments. The "Global frame" refers to the global environment, and "add_numbers" refer to the local environment for the function `add_numbers()`.

<iframe width="800" height="500" frameborder="0" src="https://pythontutor.com/iframe-embed.html#code=def%20add_numbers%28num1,%20num2%29%3A%0A%20%20%22%22%22%20Adds%20two%20input%20numbers%20together.%20%22%22%22%0A%20%20result%20%3D%20num1%20%2B%20num2%0A%20%20return%20result%0A%20%20%0Aadd_numbers%283,%204%29&amp;codeDivHeight=400&amp;codeDivWidth=350&amp;cumulative=false&amp;curInstr=0&amp;heapPrimitives=nevernest&amp;origin=opt-frontend.js&amp;py=311&amp;rawInputLstJSON=%5B%5D&amp;textReferences=false">

Expand Down Expand Up @@ -111,4 +109,4 @@ The function did not work as expected because we used hard-coded variables (`x`,

## Exercises

Exercise for week 3 can be found [here](https://colab.research.google.com/drive/1d07xM-0vCFNVFoJF32yBMvNtUsGjC_n3?usp=sharing).
Exercise for week 4 can be found [here](https://colab.research.google.com/drive/1d07xM-0vCFNVFoJF32yBMvNtUsGjC_n3?usp=sharing).
2 changes: 1 addition & 1 deletion 05-Iteration_Styles.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,4 @@ for i, value in simple_df.measurement1.items():

## Exercises

Exercise for week 4 can be found [here](https://colab.research.google.com/drive/1qrfGCF2Bh_7hjqvDg2ASXWllzw0kPw1Q?usp=sharing).
Exercise for week 5 can be found [here](https://colab.research.google.com/drive/1qrfGCF2Bh_7hjqvDg2ASXWllzw0kPw1Q?usp=sharing).
4 changes: 2 additions & 2 deletions 06-Reference_vs_Copy.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ They are the same.

Here is another visual way to think about this:

![If you imagine variables are like boxes, you can\'t make sense of assignment in Python; instead, think of variables as sticky notes. Image source: Fluent Python, Chapter 8.](images/references.png)If you imagine variables are like boxes, you can't make sense of assignment in Python; instead, think of variables as sticky notes. Image source: Fluent Python, Chapter 8.
![If you imagine variables are like boxes, you can't make sense of assignment in Python; instead, think of variables as sticky notes. Image source: Fluent Python, Chapter 8.](images/references.png)If you imagine variables are like boxes, you can't make sense of assignment in Python; instead, think of variables as sticky notes. Image source: Fluent Python, Chapter 8.

### An object isn't unique

Expand Down Expand Up @@ -281,4 +281,4 @@ This behavior is super inconsistent and confusing, as it's hard to predict when

## Exercises

Exercise for week 5 can be found [here](https://colab.research.google.com/drive/1re65RfslckVFiQB_utWNyppd3kx0PLPH?usp=sharing).
Exercise for week 6 can be found [here](https://colab.research.google.com/drive/1re65RfslckVFiQB_utWNyppd3kx0PLPH?usp=sharing).
Binary file added images/Intermediate_Python_R2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added slides/images/stickers mosaic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading