I see. Thanks for the clarification. On Dec 22, 12:35 am, Steven D'Aprano <steve +comp.lang.pyt...@pearwood.info> wrote: > 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 ...:yieldx > > > In other words, when certain condition is met, I want toyieldnothing. > > How to do? > > Actually, there's an even easier way. > > >>> def h(): > > ... if not condition: > ... for c in "abc": > ... yieldc > ... > > >>> condition = False > >>> list(h()) > ['a', 'b', 'c'] > >>> condition = True > >>> list(h()) > > [] > > -- > Steven > >
-- http://mail.python.org/mailman/listinfo/python-list