On Dec 12, 2019, at 20:51, Tim Peters <[email protected]> wrote:
> 
> BTW, you can go a long way in Python without knowing anything about `iter()` 
> or `next()`.  But not without mastering `for` loops.  That's why I prefer to 
> say that, for ordinary cases,
> 
>     a = first(it)
> 
> has the same effect as:
> 
>     for a in it:
>         break

I just had to explain to someone today that a loop like this doesn’t just use 
up and throw away a value from it, but leaves a bound to that first value.

Admittedly, this wasn't a novice, but a pretty experienced C++ and Java 
developer who doesn’t do much Python, who just didn’t know that Python scopes 
are functions rather than all compound statements. That’s not a confusion a 
novice would have.

But would a novice actually get that it is usefully assigning the first thing 
in it to a? It seems obvious to me, but I’m not sure it would to most people 
who don’t know enough Python to know about iter.

For that matter, even if they do know this leaves a bound to something useful, 
do they know what it does with a set? If not, what have we solved here?

And do we even really need to solve this problem How many novices are going to 
be confused about what first does with a set, and need to know the answer?

Plus, if first really has to be this completely understandable to people who 
don’t know about iter, how can we put it in itertools, a module whose docs 
start off with a nice friendly introduction about the building blocks of an 
algebra for iterators that you can compose into powerful tools?

_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/BPDXBX3YGYX2IYJN5FZ3EPGZYRSJVHNG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to