Standard Forth versus Python: a case study

Fredrik Lundh fredrik at pythonware.com
Fri Oct 13 02:50:44 EDT 2006


Gabriel Genellina wrote:

> At Thursday 12/10/2006 17:44, idknow at gmail.com wrote:
> 
>> > > > fun median {
>> > > >  var x = 0.
>> > > >   while( *p++) {
>> > > >     if( (*p) > x) x = *p.
>> > > >   }
>> > > >   return x.
>> > > > }
>>
>> clearly, i've forgotten the definition of the median of a list.
>> to that i plead faulty memory.
> 
> That explains all. Finding the median in an efficient way (that is, 
> without sorting the data first) isn't trivial, so your claim of "I can 
> do that using only one temp variable" was a bit surprising...
> BTW, the median is the value which sits just in the middle of the list 
> when ordered: median(3,5,12,1,2)=median(1,2,3,5,12) = 3

note that both his proposals does indeed find the median if given a list 
of zeros, though.  maybe they just used lousy sample data in that stat 
class he took?

</F>




More information about the Python-list mailing list