Streamline previous content
This includes shortening the filename of notebook 01
This commit is contained in:
parent
8e841274e6
commit
514b2dac40
4 changed files with 38 additions and 27 deletions
|
|
@ -142,7 +142,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"140620654002656"
|
||||
"139655430681056"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
|
|
@ -635,7 +635,7 @@
|
|||
"source": [
|
||||
"Code gets even more confusing when variables by the same name from different scopes collide. In particular, what should we expect to happen if a function changes a globally defined variable internally?\n",
|
||||
"\n",
|
||||
"`average_odds()` below works like `average_evens()` above except that it **[casts](https://en.wikipedia.org/wiki/Type_conversion)** (i.e., \"converts\") the elements of `numbers` as objects of type `int` with the [int()](https://docs.python.org/3/library/functions.html#int) built-in first before filtering and averaging them. In doing so, it introduces an *internal* variable `nums` whose name collides with the one in the global scope."
|
||||
"`average_odds()` below works like `average_evens()` above except that it **[casts](https://en.wikipedia.org/wiki/Type_conversion)** (i.e., \"converts\") the elements of `numbers` as objects of type `int` with the [int()](https://docs.python.org/3/library/functions.html#int) built-in first before filtering and averaging them. In doing so, it introduces an *internal* variable `nums` whose name collides with the one in the global scope. The **inequality operator** `!=` is just the **reversed** version of `==`."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -658,7 +658,7 @@
|
|||
" float: average\n",
|
||||
" \"\"\"\n",
|
||||
" nums = [int(n) for n in numbers] # cast all numbers as integers first\n",
|
||||
" odds = [n for n in nums if n % 2 != 0] # before filtering them\n",
|
||||
" odds = [n for n in nums if n % 2 != 0] # before filtering for odd numbers\n",
|
||||
" average = sum(odds) / len(odds)\n",
|
||||
" return average"
|
||||
]
|
||||
|
|
@ -2036,7 +2036,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"140620734513624"
|
||||
"139655519584648"
|
||||
]
|
||||
},
|
||||
"execution_count": 58,
|
||||
|
|
@ -2649,7 +2649,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0.4028601552264015"
|
||||
"0.12717011866176486"
|
||||
]
|
||||
},
|
||||
"execution_count": 75,
|
||||
|
|
@ -2684,7 +2684,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"<bound method Random.choice of <random.Random object at 0x561d3c7fbba8>>"
|
||||
"<bound method Random.choice of <random.Random object at 0x562161984ba8>>"
|
||||
]
|
||||
},
|
||||
"execution_count": 76,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue