On Wed, 21 Dec 2011 21:45:13 -0800, GZ wrote: > Now the question here is this: > > def h(): > if condition=true: > #I would like to return an itereator with zero length > else: > for ...: yield x > > In other words, when certain condition is met, I want to yield nothing. > How to do?
Actually, there's an even easier way. >>> def h(): ... if not condition: ... for c in "abc": ... yield c ... >>> >>> condition = False >>> list(h()) ['a', 'b', 'c'] >>> condition = True >>> list(h()) [] -- Steven -- http://mail.python.org/mailman/listinfo/python-list