map/filter/reduce/lambda opinions and background unscientific mini-survey
Dan Bishop
danb_83 at yahoo.com
Tue Jul 5 23:46:20 EDT 2005
Devan L wrote:
> Claiming that sum etc. do the same job is the whimper of
> someone who doesn't want to openly disagree with Guido.
>
> Could you give an example where sum cannot do the job(besides the
> previously mentioned product situation?
Here's a couple of examples from my own code:
# from a Banzhaf Power Index calculator
# adds things that aren't numbers
return reduce(operator.add,
(VoteDistributionTable({0: 1, v: 1}) for v in electoral_votes))
# from a custom numeric class
# converts a tuple of digits into a number
mantissa = sign * reduce(lambda a, b: 10 * a + b, mantissa)
> Also, map is easily replaced.
> map(f1, sequence) == [f1(element) for element in sequence]
There's also the issue of having to rewrite old code.
More information about the Python-list
mailing list