Defending the ternary operator
hamonlypaulpaterson at houston.rr.com
Mon Feb 10 05:48:28 CET 2003
"Dennis Lee Bieber" <wlfraed at ix.netcom.com> wrote in message
news:bqbjh-nj3.ln1 at beastie.ix.netcom.com...
> Paul Paterson fed this fish to the penguins on Saturday 08 February
> 2003 05:14 pm:
> > structure finds 769 matches of the following pattern,
> > if <something>
> > variable = <some value>
> > else:
> > variable = <some other value>
> > in 381209 lines of code. I leave the statistical interpretation to the
> > reader.
> Ah, but perhaps the better statistic would be to also know how
> if <something>:
> <do something>
> <do something else>
> appear in the code referenced. If your 769 were 50% of the total
> if/else code, then a conditional might be a desirable feature. If 5%
> then it probably doesn't gain enough to justify adding it.
> Oh, what about?
> if <s1>:
> v = <some1>
> elif <s2>:
> v = <some2>
> v = <some...>
> v = <else>
> A conditional expression won't replace that (though unless each
> <somen> is a dynamic equation, a list/dictionary look-up is likely
A minor modification could find both these statistics. The code is here,
More information about the Python-list