urikaluzhny wrote: > It seems that I rather frequently need a list or iterator of the form > [x for x in <> while <>] > And there is no one like this. > May be there is another short way to write it (not as a loop). Is > there? > Thanks
I usually have the same problem and i came up with an solution like that: from operator import ne def test(iterable, value, op=ne): _n = iter(iterable).next while True: _x = _n() if op(_x, value): yield _x else: raise StopIteration l = range(6) print [x for x in test(l, 4)] [EMAIL PROTECTED]:~/tmp> python test18.py [0, 1, 2, 3] -- http://mail.python.org/mailman/listinfo/python-list