> 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))

return sum([VoteDistributionTable({0:1, v:1} for v in
electoral_votes],VoteDistributionTable({}))
Any time you use operator.add, you can probably use
sum(sequence,initialvalue)

> # from a custom numeric class
> # converts a tuple of digits into a number
> mantissa = sign * reduce(lambda a, b: 10 * a + b, mantissa)

I'll admit I can't figure out a way to replace reduce without writing
some ugly code here, but I doubt these sorts of things appear often.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to