Asun Friere <[EMAIL PROTECTED]> writes:

 > A canonical use of the conditional operator is in
 > pluralising words, (eg. '%s dollar' % n + 's' if n!=1 else '').

That fails for n == 1.  So what is best?

for i in range(4):
    print '%d thing' % i + ('s' if i != 1 else '')

for i in range(4):
    print '%d thing%s' % (i, ('s', '')[i==1])

for i in range(4):
    print '%d thing%s' % (i, 's' if i != 1 else '')


-- 
Pete Forman                -./\.-  Disclaimer: This post is originated
WesternGeco                  -./\.-   by myself and does not represent
[EMAIL PROTECTED]    -./\.-   the opinion of Schlumberger or
http://petef.22web.net           -./\.-   WesternGeco.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to