reduce()--what is it good for? (was: Re: reduce() anomaly?)

Andrew Dalke adalke at mindspring.com
Tue Nov 18 02:28:14 EST 2003


Georgy Pruss:
> I NEVER wondered which of constructions should I
> use in any particular case. I just solved the problem and wrote its
solution
> in that language and the language HELPED me to express myself clearly.

While I, when writing Perl code, also NEVER had a problem.  I
ignored just about all of its variations
  if ($cond) {$a++}
  $a++ if $cond;
  $a++ unless !($cond);
  unless (!($cond)) {$a++};

I almost only used the first of these, and when other variations
in structure came up I again had a strong preference for the one
closest to C in feel.  I did this not because it was the most expressive
but because I wanted to write code that others could follow,
and indeed one of the praises I got was "wow! It's Perl code I
can actually understand!"

> Half of all the conditions in real Python programs are 1 or True. :-)

Cute as a joke, but in real-life it omits while loops, wherein
the conditionals usually end up being true.  ;)

x = 1
while x < 1000:
  print x
  x = x + random.random(10)

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list