Proposed new collection methods

Christopher Subich spam.csubich+block at block.subich.spam.com
Sun Aug 7 03:58:13 EDT 2005


Jeff Schwab wrote:
> Robert Kern wrote:
>> Now, if I were to do
>>
>>   item = g(self, test).next()
>>
>> the generator would execute the code until it reached the yield 
>> statement which happens when it finds the first item that passes the 
>> test. That item will get returned, and execution does not return to 
>> the generator again.
[snip]
> Wow, that's cool!  Very reminiscent of C++ input iterators, but a lot 
> cleaner and shorter.  Thanks.

Read up on the __iter__ and __next__ methods that can be implemented by 
objects; Python objects have a very nice way of becoming (and returning) 
iterators.  Generator functions and expressions are magic ways of doing 
some Really Common Things as iterators.



More information about the Python-list mailing list