diff --git a/docs/_quarto.yml b/docs/_quarto.yml index d57198c..4b3a56e 100644 --- a/docs/_quarto.yml +++ b/docs/_quarto.yml @@ -124,15 +124,14 @@ book: chapters: - href: notes/data-processing/for-loops.qmd text: "List Iteration and Looping" - - href: notes/data-processing/sorting.qmd - text: "List Sorting" - href: notes/data-processing/mapping.qmd text: "List Mapping" - href: notes/data-processing/filtering.qmd text: "List Filtering" - href: notes/data-processing/list-comprehensions.qmd text: "List Comprehensions" - + - href: notes/data-processing/sorting.qmd + text: "List Sorting" - part: "Data Visualization" chapters: diff --git a/docs/notes/data-processing/for-loops.qmd b/docs/notes/data-processing/for-loops.qmd index 3fe1de7..cea3bd9 100644 --- a/docs/notes/data-processing/for-loops.qmd +++ b/docs/notes/data-processing/for-loops.qmd @@ -20,7 +20,7 @@ print(symbols) We saw how we can print and access all items at once. And we saw we can use an index reference to access a specific item. But what if we want to access each item individually, however many there are? -We can use a **\"for\" loop** to access each item one at a time: +We can use a **\"for\" loop** to access each item, one at a time: ```{python} print("TOP") @@ -33,7 +33,21 @@ for item in symbols: print("BOTTOM") ``` -When we use a \"for\" loop, we have to fill in some slots. We have no choice but to put the list we want to loop through in the second slot (after the `in`). But we have an absolute arbitrary choice of what variable name to use to reference each item (after the `for`). Whatever variable name we choose (e.g. `x`), we must also reference that variable within the scope of the loop: +When we use a \"for\" loop, we have to fill in some slots. To understand the slots, see the following pseudocode: + +```python +for _________ in _________: + _________ +``` + + +```python +for VARIABLE_REFERENCE_FOR_EACH_ITEM in EXISTING_LIST: + DO_SOMETHING_WITH_THAT_ITEM +``` + + +We have no choice but to put the list we want to loop through in the second slot (after the `in`). But we have an absolute arbitrary choice of what variable name to use to reference each item (after the `for`). Whatever variable name we choose (e.g. `x`), we must also reference that variable within the scope of the loop: ```{python} print("TOP") @@ -46,7 +60,7 @@ for x in symbols: print("BOTTOM") ``` -In practice, if we have a list of items plural (`symbols`), we could call each item the singular version (`symbol`) to make our code readable: +As a best practice, if we have a list of items plural (e.g. `symbols`), we could call each item the singular version (e.g. `symbol`) to make our code readable: ```{python} print("TOP") @@ -59,4 +73,4 @@ for symbol in symbols: print("BOTTOM") ``` -Loops are essential and foundational. They will form the basis of more advanced operations, such as [mapping](./mapping.qmd) and [filtering](./filtering.qmd). +The \"for\" loop is an essential and foundational technique, which will form the basis of more advanced operations, such as [mapping](./mapping.qmd) and [filtering](./filtering.qmd). diff --git a/docs/notes/dataviz/overview.qmd b/docs/notes/dataviz/overview.qmd index f4b5461..ff944d0 100644 --- a/docs/notes/dataviz/overview.qmd +++ b/docs/notes/dataviz/overview.qmd @@ -100,7 +100,7 @@ print(viewers) ```{python} from plotly.express import bar -fig = bar(x=dates, y=prices, height=350, +fig = bar(x=genres, y=viewers, height=350, title="Viewership by Genre", labels={"x": "Genre", "y": "Viewers"} ) diff --git a/docs/notes/python-lang/basic-datatypes/strings.qmd b/docs/notes/python-lang/basic-datatypes/strings.qmd index 9beec16..54f04c1 100644 --- a/docs/notes/python-lang/basic-datatypes/strings.qmd +++ b/docs/notes/python-lang/basic-datatypes/strings.qmd @@ -35,7 +35,7 @@ Multiline string, uses triple quotes (`"""`) on the extremities: ```{python} message = """ -This is a menu for our trading platform. +This is a menu for our application. To get started, follow these instructions: diff --git a/docs/notes/python-lang/control-flow/conditional-logic.qmd b/docs/notes/python-lang/control-flow/conditional-logic.qmd index 210b966..5118ff0 100644 --- a/docs/notes/python-lang/control-flow/conditional-logic.qmd +++ b/docs/notes/python-lang/control-flow/conditional-logic.qmd @@ -52,16 +52,16 @@ Observe that the "else" clause is optional, and will represent a catch-all condi ```{python} print("TOP") -if 2 + 2 == 4: - print("THEY ARE EQUAL") - print("MORE STUFF") +if 2 + 2 == 5: + print("THEY ARE EQUAL") # NEVER REACHED + print("MORE STUFF") # NEVER REACHED else: - print("THEY ARE NOT EQUAL") # NEVER REACHED + print("THEY ARE NOT EQUAL") print("BOTTOM") ``` -To implement multiple conditions, we can optionally include any number of "elif" clauses. They must come AFTER the "if", and BEFORE the "else": +To implement multiple conditions, we can optionally include any number of "elif" clauses. They must come AFTER the "if", and BEFORE the "else" (if there is one present): ```{python} print("TOP") @@ -78,6 +78,9 @@ else: print("BOTTOM") ``` +One way you can think about the "elif" clause is that it is like an "else" clause, but with an associated condition. + + Observe that if more than one condition evaluates to being true, whichever is listed FIRST will be reached: ```{python} diff --git a/docs/notes/python-lang/control-flow/index.qmd b/docs/notes/python-lang/control-flow/index.qmd index b7b6824..325bff7 100644 --- a/docs/notes/python-lang/control-flow/index.qmd +++ b/docs/notes/python-lang/control-flow/index.qmd @@ -20,4 +20,13 @@ Understanding how indentation controls scope helps us write clean, readable code -Control flow structures in Python include [conditionals](conditional-logic.qmd) (\"if\" statements), [custom functions](custom-functions.qmd), [error handling](errors.qmd), and loops (\"for" loops vs [\"while\" loops](while-loops.qmd)). We will study most of these structures in this chapter, then we will return later to cover [\"for\" loops](../../data-processing/for-loops.qmd) after studying the [`list` datatype](../container-datatypes/lists.qmd) in more detail. +Control flow structures in Python include: + + + [Conditionals](conditional-logic.qmd) (\"If\" Statements) + + [Custom Functions](custom-functions.qmd) + + [Error Handling](errors.qmd) + + Loops: + + [\"For" loops](../../data-processing/for-loops.qmd) + + [\"While\" loops](while-loops.qmd) + +We will study most of these structures in this section, then we will return later to cover \"for\" loops after studying the [`list` datatype](../container-datatypes/lists.qmd) in more detail.