On Sep 24, 8:40 pm, Asun Friere <[EMAIL PROTECTED]> wrote: > On Sep 25, 3:16 am, Pete Forman <[EMAIL PROTECTED]> wrote: > > > 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? > > Sorry missing parantheses. I should test, even for fragments written > out as part of a sentence. %-/ > > > for i in range(4): > > print '%d thing' % i + ('s' if i != 1 else '') > > That's the corrected version of what I meant, but actually I think > your last version ('%d thing%s' % (i, 's' if i != 1 else '')), holding > all variables for placeholders in the tuple, is better. It's certainly > more readible.
It's a different answer if you have 'things is/are'. '%d thing%s %s'% ( ( i, )+ ( 's', 'are' ) if i!= 1 else ( '', 'is' ) ). Or excluding prepositional phrases and subordinate clauses, '%d thing%s'% ( i, 's are' if i!= 1 else ' is' ). -- http://mail.python.org/mailman/listinfo/python-list