fixed for-loop example

This commit is contained in:
Sebastian Raschka 2014-04-29 21:38:56 -04:00
parent c3fc8395e2
commit 3e6588120f

View File

@ -593,7 +593,8 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Similar to the concept of the `global` keyword, which we have seen in the section above, we can use the keyword `nonlocal` inside the inner function to explicitely access a variable from the outer (enclosed) scope in order to modify its value:" "Similar to the concept of the `global` keyword, which we have seen in the section above, we can use the keyword `nonlocal` inside the inner function to explicitely access a variable from the outer (enclosed) scope in order to modify its value. \n",
"Note that the `nonlocal` keyword was added in Python 3.x and is not implemented in Python 2.x (yet)."
] ]
}, },
{ {
@ -1045,12 +1046,13 @@
] ]
}, },
{ {
"cell_type": "code", "cell_type": "markdown",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {}, "metadata": {},
"outputs": [] "source": [
"This goes back to a change that was made in Python 3.x and is described in [What\u2019s New In Python 3.0](https://docs.python.org/3/whatsnew/3.0.html) as follows:\n",
"\n",
"\"List comprehensions no longer support the syntactic form `[... for var in item1, item2, ...]`. Use `[... for var in (item1, item2, ...)]` instead. Also note that list comprehensions have different semantics: they are closer to syntactic sugar for a generator expression inside a `list()` constructor, and in particular the loop control variables are no longer leaked into the surrounding scope.\""
]
} }
], ],
"metadata": {} "metadata": {}