Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41144
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Finding the Min for positive and negative in python 3.3 list |
| Date | 2013-03-12 13:57 -0400 |
| References | <abcd1234abc123ab12a0000000027000020000001052@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3245.1363111060.2939.python-list@python.org> (permalink) |
On 3/12/2013 1:03 PM, Norah Jones wrote: > For example: > a=[-15,-30,-10,1,3,5] > > I want to find a negative and a positive minimum. > > example: negative > print(min(a)) = -30 > > positive > print(min(a)) = 1 If this is homework, stop reading and do it yourself ;-) Otherwise... >>> min(i for i in a if i >0) 1 >>> max(i for i in a if i < 0) -10 >>> min(i for i in a if i < 0) -30 You did not specify if you would include 0 in a pos min (0 is neither really positive or negative). -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Finding the Min for positive and negative in python 3.3 list Terry Reedy <tjreedy@udel.edu> - 2013-03-12 13:57 -0400
csiph-web