On Jul 2, 11:55 pm, Paul Rubin <http://phr...@nospam.invalid> wrote: > Yeah, it should allow supplying a predicate instead of using == on > a value. How about (untested): > > from itertools import * > ... > for row in takewhile(lambda x: x is sentinel, > starmap(in_queue.get, repeat(()))): > ...
Yeah, it's a small recipe I'm sure a lot of others have written as well. My old version: def iterwhile(callable_, predicate): """ Like iter() but with a predicate instead of a sentinel. """ return itertools.takewhile(predicate, repeatfunc(callable_)) where repeatfunc is as defined here: http://docs.python.org/library/itertools.html#recipes I wish all of these little recipes made their way into itertools or a like module; itertools seems a bit tightly guarded. -- http://mail.python.org/mailman/listinfo/python-list