A variant of this question has been asked in the past. However, I wasn't able to get the responses working for me. This is a sample dict I have:
{rdflib.term.URIRef(u'<http://purl.org/net/ontology#isGivenDrugA>'): rdflib.term.Literal(u'<http://purl.org/net/ontology#dose1>')}
{rdflib.term.URIRef(u'<http://purl.org/net/ontology#isGivenDrugB>'): rdflib.term.Literal(u'<http://purl.org/net/ontology#dose2>')}
{rdflib.term.URIRef(u'<http://purl.org/net/ontology#isGivenDrugC>'): rdflib.term.Literal(u'<http://purl.org/net/ontology#dose3>')}
I want to rename the first term in each of the dicts to isNotGivenDrugA
or B or C. For instance:
{rdflib.term.URIRef(u'<http://purl.org/net/ontology#isNotGivenDrugA>'): rdflib.term.Literal(u'<http://purl.org/net/ontology#dose1>')}
How can I do so?
This is the code I have so far:
for s in notGivenDrugList:
print ('s: ',s)
for k,v in s.iteritems():
print k
k
gives me the first term of each dict. If I assign it a value based on k.replace
, that doesn't work as keys of dict are immutable and iteritems
only creates copies of the key.