title: Iterating over a SPARQL query with RDFLib
body: <p>I have a SPARQL query that retrieves all the nodes linked to the classes in an ontology of the human anatomy: </p>
  
  <pre><code>queryloop=graph.query("""SELECT ?node ?othernodes ?othernodesLabel WHERE { 
  ?node rdf:type owl:Class .
  ?node ?y ?othernodes .
  ?othernodes rdfs:label ?othernodesLabel
  } 
  LIMIT 100""")
  </code></pre>
  
  <p>I now need to iterate over the results and group the labels in a python dictionary, so that the key contains the label of the class (<code>?node</code>), and the value contains the labels of the adjoining nodes, so that for every class in the ontology there is a dictionary key (and for each key there are as many values as adjoining classes). I don't know how variable bindings work in rdflib so I don't know how to write a for-loop in python that would have access to the SPARQL query. </p>