Help with sets

B. M. Whealton bwhealton at
Tue Oct 5 04:31:50 CEST 2010

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
        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, 
         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, 

Thanks for any help and insights into this,

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

More information about the Python-list mailing list