Proposal: function which simulates C ?: operator
Paul Rubin
http
Sun Jul 11 13:57:00 EDT 2004
More information about the Python-list mailing list
Sun Jul 11 13:57:00 EDT 2004
- Previous message (by thread): Proposal: function which simulates C ?: operator
- Next message (by thread): Proposal: function which simulates C ?: operator
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Adal Chiriliuc <me at spammers.com> writes: > I think a function similar to the one below should be added to the > builtin module: > > def boolselect(condition, trueresult, falseresult): > if condition: > return trueresult > else: > return falseresult That doesn't work because both results get evaluated either way. E.g. boolselect(x==0, f(x), g(x)) calls both f and g. You need something like (lambda: g(x), lambda: f(x))[bool(condition)]()
- Previous message (by thread): Proposal: function which simulates C ?: operator
- Next message (by thread): Proposal: function which simulates C ?: operator
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list