4e7b63c4546bfa43797a11f77d3032274cee0e02 wong Fri Jan 13 11:58:28 2012 -0800 added comments and made variable names better diff --git python/lib/ucscgenomics/ra.py python/lib/ucscgenomics/ra.py index 550afba..e459aab 100644 --- python/lib/ucscgenomics/ra.py +++ python/lib/ucscgenomics/ra.py @@ -378,39 +378,41 @@ are overwritten (or inserted if not found) into 'self'. Final merged dictionary is returned. ''' ret = self common = set(self.iterkeys()) & set(other.iterkeys()) for stanza in common: if term not in self[stanza] and term not in other[stanza]: continue if term in self[stanza] and term not in other[stanza]: del ret[stanza][term] continue if term in other[stanza]: #Remake stanza to keep order of terms tempStanza = RaStanza() tempStanza._name = stanza - selfListItor = list(self[stanza].iterkeys()) - otherListItor = list(other[stanza].iterkeys()) + selfKeys = list(self[stanza].iterkeys()) + otherKeys = list(other[stanza].iterkeys()) newOther = list() - for i in otherListItor: - if not i in selfListItor and i != term: + #filter out keys in other that aren't in self, or the term we're interested in + for i in otherKeys: + if not i in selfKeys and i != term: continue else: newOther.append(i) - masterList = ucscUtils.mergeList(newOther, selfListItor) + #merge self keylist and filtered other list + masterList = ucscUtils.mergeList(newOther, selfKeys) for i in masterList: if i == term: tempStanza[i] = other[stanza][i] else: tempStanza[i] = self[stanza][i] ret[stanza] = tempStanza return ret def __str__(self): str = '' for item in self.iteritems(): if len(item) == 1: str += item[0].__str__() + '\n' else: