For review: PEP 308 - If-then-else expression
Andrew Koenig
ark at research.att.com
Sat Feb 8 09:44:22 EST 2003
Erik> In my opinion, the key issue about the benefit of a conditional
Erik> operator is about making code more readable. If I see
Erik> 's'[:count!=1] I certainly have to sit and think about it a
Erik> little bit; it's hardly a crystal clear idiom.
Erik> ('', 's')[count != 1] is a tiny bit better since it's a
Erik> slightly more recognized idiom (and I've certainly used it on
Erik> occasion), but it's still not immediately clear.
In this particular case, I think { True: 's', False: '' }[count == 1]
is even easier to understand -- but I'd still prefer
's' if count==1 else ''
--
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list
mailing list