Ten awesome things you are missing out on if you're still using Python 2
Tim Chase
python.list at tim.thechases.com
Mon May 8 22:09:06 EDT 2017
On 2017-05-08 07:17, Steven D'Aprano wrote:
> http://www.asmeurer.com/python3-presentation/slides.html#1
Just adding my regular beef about #5, the "everything is an
iterator" in regards to the new tuple-unpacking when the wild-card
is in the last position:
>>> a,b, *c = range(10)
>>> a
0
>>> b
1
>>> c
[2, 3, 4, 5, 6, 7, 8, 9]
>>> type(c)
<class 'list'>
I've had multiple occasions where I don't care about the rest, yet
don't want to consume them. Take for example
a, b, *c = itertools.count()
It would be perfectly sensible to have it result in
>>> a
0
>>> b
1
>>> c
count(2)
>>> type(c)
<class 'itertools.count'>
However, because it attempts to consume the iterator before
assigning it to `c`, the code will hang until it has completely
exhausted memory. As it says further on in #5, "If you want a list,
just wrap the result with list."
Just a personal pet peeve here. :-)
> (The web UI is a bit ~~crap~~ minimialist. Use the left and right
> arrow keys to advance backwards and forwards among the slides.)
Additionally, classic vi keys of j/k work nicely, as do
page-up/page-down, and <space> works to advance a page at a time as
well.
-tkc
More information about the Python-list
mailing list