Re: Standard Forth versus Python: a case study

2006-10-13 Thread B M
i hang my head in shame.



On 10/12/06, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> At Thursday 12/10/2006 17:44, [EMAIL PROTECTED] 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
>
>
> --
> Gabriel Genellina
> Softlab SRL
>
>
>   
>   
>   
> __
> Preguntá. Respondé. Descubrí.
> Todo lo que querías saber, y lo que ni imaginabas,
> está en Yahoo! Respuestas (Beta).
> ¡Probalo ya!
> http://www.yahoo.com.ar/respuestas
>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Help with sets

2010-10-04 Thread B. M. Whealton

Hello all,
 So, I started learning python just recently.  I got inspired
by a project that related to the semantic web.  I can see why this would
be a language chosen for the applications that help to build the
semantic web.  It is interesting to see that indeed python does have
structures that make it well suited for this kind of application, or I
seem to be able to see how certain structures in python do stand out as
unique and related to concepts I am reading about in relation to the
Semantic web.  I did get a bit confused in reading about the concept of
sets in python and why you would use them instead of a dictionary for
example.
   For example, here we have:
self._pos = {predicate:{object:set([subject])}}
This is said to be a dictionary, containing dictionaries, which in turn
contain sets. I don't know if it would be possible to explain why one
would use a set, especially in this context without showing more.  I was
a bit stumped by this for some odd reason.  I don't know if other
languages lack certain structures and features.  It's been a long time
since I did C programming too.
   Anyway, this would be used an a Class as follows:

class SimpleGraph:
def __init__(self):
 self._spo = {}
 self._pos = {}
 self._osp = {}

This is to create indexes that are permutations of the pattern subject,
predicate object.  So, using this:

self._pos = {predicate:{object:set([subject])}}

   We have the first dictionary keyed off the first term, the 
second dictionary keyed off the second term, and the set containing the 
third terms(note terms plural). I guess I somewhat understand that sets 
are used to test for membership.  Cannot that be done with dictionaries, 
though?
Also, if you ran this for loop, below, what is being yielded, 
the key or the value in the dictionary?  I refer to this for loop here:
for subject in self._pos[predicate][ojbect]: yield (subject, predicate, 
object)


Thanks for any help and insights into this,
Bruce
--

++++++++
B. M. Whealton - Web Developer, Programmer, Owner:
Future Wave Designs: http://FutureWaveDesigns.com
"On Being a Poet and Other Existential Ideas":>
http://WordSaladPoetryMagazine.com/words/
Publisher of Word Salad Poetry Magazine:
http://WordSaladPoetryMagazine.com/ - Submit your poetry


--
http://mail.python.org/mailman/listinfo/python-list