Feature suggestion: math.zod for painlessly avoiding ZeroDivisionError

Natan Yellin aantny at gmail.com
Mon Apr 11 16:26:03 CEST 2011


On Mon, Apr 11, 2011 at 5:20 PM, Chris Angelico <rosuav at gmail.com> wrote:

> On Tue, Apr 12, 2011 at 12:10 AM, Natan Yellin <aantny at gmail.com> wrote:
> > Hey everyone,
> > This is my first posting to python-list, so be gentle.
> > I propose the following function for the math module (which can, of
> course,
> > be rewritten in C):
> >>
> >>  zod = lambda a, b: b and a / b
> >
> > If y can be zero, that one-liner needs to be rewritten as:
> >>
> >> if y != 0:
> >>     stat = x / y
> >> else:
> >>     stat = 0
>
> You can optimize that the same way as your zod function:
> stat = y and x/y

I'm dealing with long-named variables inside of dictionaries, which makes
that impractical.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110411/a61d68a8/attachment.html>


More information about the Python-list mailing list