While skimming through Python-Dev Archives I came across an interesting post by Chad Netzer on a Python equivlent for a common use of the ternary operator in C.
On Thu, 2003-02-06 at 17:38, Ka-Ping Yee wrote:
> For example, here's a common idiom i use in C:
>
> printf("Read %d file%s.", count, count == 1 ? "" : "s");
Just for giggles, here is a python version:
print "Read %d file%s." % (count, {1:""}.get(count,"s"))
The whole post can be found here: http://mail.python.org/pipermail/python-dev/2003-February/033147.html
Posted Friday, February 07, 2003 at 03:05 PM
View February, 2003, latest entries, or archive