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


Groups > comp.lang.python > #41143 > unrolled thread

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

Started byDevin Jeanpierre <jeanpierreda@gmail.com>
First post2013-03-12 13:49 -0400
Last post2013-03-12 13:49 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

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

FromDevin Jeanpierre <jeanpierreda@gmail.com>
Date2013-03-12 13:49 -0400
SubjectRe: Finding the Min for positive and negative in python 3.3 list
Message-ID<mailman.3244.1363110630.2939.python-list@python.org>
> 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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web