A small quiz

Peter Otten __peter__ at web.de
Fri Jan 3 13:01:32 EST 2020


Alan Bawden wrote:

> ram at zedat.fu-berlin.de (Stefan Ram) writes:
> ...
>>   So I was looking for a predefined object from the standard
>>   library that already /is/ an iterator (with no need to use
>>   »iter«).
>> 
>>   I found exactly one such object (which can be used after a
>>   »from ... import ...« statement). Can you guess what it is?
> 
> Well, there's sys.stdin.
> 
> But I would expect beginning students to find the effect of typing
> "next(sys.stdin)" to the commnd prompt to be a bit confusing...
> 

There are a lot of itertools.count() objects, e. g.

>>> from multiprocessing.pool import job_counter
>>> next(job_counter)
0
>>> next(job_counter)
1




More information about the Python-list mailing list