Generator Question
GZ
zyzhu2000 at gmail.com
Sat Dec 24 16:19:44 EST 2011
More information about the Python-list mailing list
Sat Dec 24 16:19:44 EST 2011
- Previous message (by thread): Generator Question
- Next message (by thread): Adding an interface to existing classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I see. Thanks for the clarification. On Dec 22, 12:35 am, Steven D'Aprano <steve +comp.lang.pyt... at 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 > >
- Previous message (by thread): Generator Question
- Next message (by thread): Adding an interface to existing classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list