the PHP ternary operator equivalent on Python

Fredrik Lundh fredrik at pythonware.com
Thu Nov 24 02:41:39 EST 2005


rurpy at yahoo.com wrote:

> I don't find your code any more readable than the OP's
> equivalent code:

the OP's question was

    How you do this in a practic way without
    the use of one-line code ?

> The OPs code make one pass through the dict, your's makes
> two.  I do not know what effect (if any) that has in the case of
> a very large dict.

the OPs code contains five reads and three writes, my and
steven's versions contain four reads and three writes.  the
yet-to-be-released ternary operator would remove one read
from the OPs code, which makes both alternatives equivalent.

dictionary accesses don't involve passes over the dictionary.

there's a comment on readability and code understanding waiting
to be made here, but I'll leave that for another day.

</F>






More information about the Python-list mailing list