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

2013-03-14 Thread 88888 Dihedral
Wolfgang Maier於 2013年3月13日星期三UTC+8下午6時43分38秒寫道: > Steven D'Aprano pearwood.info> writes: > > > > > > > > On Tue, 12 Mar 2013 17:03:08 +, Norah Jones wrote: > > > > > > > For example: > > > > a=[-15,-30,-10,1,3,5] > > > > > > > > I want to find a negative and a positive minimum. >

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

2013-03-13 Thread Mark Lawrence
On 13/03/2013 14:12, Steven D'Aprano wrote: On Wed, 13 Mar 2013 11:23:22 +, Oscar Benjamin wrote: On 13 March 2013 10:43, Wolfgang Maier wrote: thinking again about the question, then the min() solutions suggested so far certainly do the job and they are easy to understand. However, if y

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

2013-03-13 Thread Wolfgang Maier
Chris Angelico gmail.com> writes: > > > Sort cannot be O(log(n)) and it cannot be faster than a standard O(n) > > minimum finding algorithm. No valid sorting algorithm can have even a > > best case performance that is better than O(n). This is because it > > takes O(n) just to verify that a list

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

2013-03-13 Thread Steven D'Aprano
On Wed, 13 Mar 2013 11:23:22 +, Oscar Benjamin wrote: > On 13 March 2013 10:43, Wolfgang Maier > wrote: >> >> thinking again about the question, then the min() solutions suggested >> so far certainly do the job and they are easy to understand. However, >> if you need to run the function repea

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

2013-03-13 Thread Peter Otten
Wolfgang Maier wrote: > Oscar Benjamin gmail.com> writes: > >> >> Sort cannot be O(log(n)) and it cannot be faster than a standard O(n) >> minimum finding algorithm. No valid sorting algorithm can have even a >> best case performance that is better than O(n). This is because it >> takes O(n) ju

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

2013-03-13 Thread Chris Angelico
On Wed, Mar 13, 2013 at 10:34 PM, Wolfgang Maier wrote: > Oscar Benjamin gmail.com> writes: > >> >> Sort cannot be O(log(n)) and it cannot be faster than a standard O(n) >> minimum finding algorithm. No valid sorting algorithm can have even a >> best case performance that is better than O(n). Thi

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

2013-03-13 Thread Chris Angelico
On Wed, Mar 13, 2013 at 10:23 PM, Oscar Benjamin wrote: > On 13 March 2013 10:43, Wolfgang Maier > wrote: >> >> thinking again about the question, then the min() solutions suggested so far >> certainly do the job and they are easy to understand. >> However, if you need to run the function repeate

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

2013-03-13 Thread Wolfgang Maier
Oscar Benjamin gmail.com> writes: > > Sort cannot be O(log(n)) and it cannot be faster than a standard O(n) > minimum finding algorithm. No valid sorting algorithm can have even a > best case performance that is better than O(n). This is because it > takes O(n) just to verify that a list is sort

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

2013-03-13 Thread Oscar Benjamin
On 13 March 2013 10:43, Wolfgang Maier wrote: > > thinking again about the question, then the min() solutions suggested so far > certainly do the job and they are easy to understand. > However, if you need to run the function repeatedly on larger lists, using > min() > is suboptimal because its p

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

2013-03-13 Thread Wolfgang Maier
Steven D'Aprano pearwood.info> writes: > > On Tue, 12 Mar 2013 17:03:08 +, 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 >

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

2013-03-12 Thread Steven D'Aprano
On Tue, 12 Mar 2013 17:03:08 +, 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 Thank you for providing examples, but they don't really cover all th

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

2013-03-12 Thread Wolfgang Maier
Wolfgang Maier biologie.uni-freiburg.de> writes: > > Norah Jones gmail.com> writes: > > > > > 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 > > > > > > > > try t

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

2013-03-12 Thread Terry Reedy
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

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

2013-03-12 Thread Devin Jeanpierre
> 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

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

2013-03-12 Thread Wolfgang Maier
Norah Jones gmail.com> writes: > > 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 > > > try this: min(a) => -30 min([n for n in a if i>0]) => 1 of course, you have to figur

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

2013-03-12 Thread Jean-Michel Pichavant
- Original Message - > 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 > -- > http://mail.python.org/mailman/listinfo/python-list min(a) and min([e for e in a if e >=0]

Finding the Min for positive and negative in python 3.3 list

2013-03-12 Thread Norah Jones
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 -- http://mail.python.org/mailman/listinfo/python-list