On Fri, Jan 31, 2014 at 7:28 AM, Ian Kelly <ian.g.ke...@gmail.com> wrote:
> Of course if you're at all concerned about i18n then the proper way to
> do it would be:
>
> ngettext("You have scored %d point", "You have scored %d points", score) % 
> score

Ugh, so much duplication! We can totally do better than that.

ngettext(*(lambda x,s: (x,x+'s',s))("You have scored %d point",score))

Much better!


Incidentally, in creating the above abomination, I found that I can't do this:

>>> print(*(lambda x: (x,x+'s'))("You have scored %d point"),score)
SyntaxError: only named arguments may follow *expression

But I can do this:

>>> print(score,*(lambda x: (x,x+'s'))("You have scored %d point"))
1 You have scored %d point You have scored %d points

Why is tuple unpacking limited to the last argument? Is it just for
the parallel with the function definition, where anything following it
is keyword-only?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to