Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41143

Re: Finding the Min for positive and negative in python 3.3 list

References <abcd1234abc123ab12a0000000027000020000001052@gmail.com> <1604147031.4067302.1363110301286.JavaMail.root@sequans.com>
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date 2013-03-12 13:49 -0400
Subject Re: Finding the Min for positive and negative in python 3.3 list
Newsgroups comp.lang.python
Message-ID <mailman.3244.1363110630.2939.python-list@python.org> (permalink)

Show all headers | View raw


> min(a)

This does not return a negative minimum on input [1] (because there is none).

> and
>
> min([e for e in a if e >=0]

This does not return a positive minimum on input [0] (because there is none).

I would have said:

    pos_min = min(e for e in a if e > 0)
    neg_min = min(e for e in a if e < 0)

And then deal with the ValueError when there is no such minimum, as appropriate.

-- Devin

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Finding the Min for positive and negative in python 3.3 list Devin Jeanpierre <jeanpierreda@gmail.com> - 2013-03-12 13:49 -0400

csiph-web