Robert Kern wrote: > (s for s in iter(self) is test(s)) is a generator expression. It is > roughly equivalent to > > def g(self, test=lambda x: True): > for s in iter(self): > if test(s): > yield s > > 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. > > That implementation does indeed return as soon as it locates the first > item, so yes, I was being retarded.
Wow, that's cool! Very reminiscent of C++ input iterators, but a lot cleaner and shorter. Thanks. -- http://mail.python.org/mailman/listinfo/python-list