def __init__(self, saveimg=False, saveto=None): self.fsetdict = {} self.util = util() self.saveimg = saveimg self.saveto = saveto if saveimg and saveto: self.drawtool = drawtree()
def __init__(self,saveimg=False,saveto=None): self.fsetdict={} self.util=util() self.saveimg=saveimg self.saveto=saveto if saveimg and saveto: self.drawtool=drawtree()
def show(self,i=0,drawtool=drawtree.drawtree().showdraw): if not drawtool: return elif drawtool=='print': if self.root: print(self.getnodetext()) else: indent=" "*i print(indent+self.getnodetext()) i+=1 for child in self.children: child.show(i=i) else: drawtool(self)
def nthlargest(root, nth): vis = [0] node = inord(root, nth, vis) if node: return node.val return None head = None lenarr = 10 arr = [] for i in xrange(lenarr): arr.append(random.randint(1, 100)) head = insert(head, arr[i]) print print nthlargest(head, 3) arr.sort() print arr[-3] drawtree.drawtree(head) print display(head) print display_itr(head) print display_morris(head)
use = doc.getElementsByTagName('useCode')[0].firstChild.data year = doc.getElementsByTagName('yearBuilt')[0].firstChild.data bath = doc.getElementsByTagName('bathrooms')[0].firstChild.data bed = doc.getElementsByTagName('bedrooms')[0].firstChild.data #rooms = doc.getElementsByTagName('totalRooms')[0].firstChild.data price = doc.getElementsByTagName('amount')[0].firstChild.data except Exception, e: #print e return None #return zipcode, use, int(year), float(bath), int(bed), int(rooms), price return zipcode, use, int(year), float(bath), int(bed), price def getpricelist(): return filter(None, [ getaddressdata(line.strip(), 'Cambridge,MA') for line in open('addresslist.txt') ]) if __name__ == '__main__': import drawtree import treepredict housedata = getpricelist() print housedata tree = treepredict.buildtree(housedata, scorefun=treepredict.variance) drawtree.drawtree(tree, 'zillow.png') print "Wrote zillow.png"
try: zipcode = doc.getElementsByTagName('zipcode')[0].firstChild.data use = doc.getElementsByTagName('useCode')[0].firstChild.data year = doc.getElementsByTagName('yearBuilt')[0].firstChild.data bath = doc.getElementsByTagName('bathrooms')[0].firstChild.data bed = doc.getElementsByTagName('bedrooms')[0].firstChild.data #rooms = doc.getElementsByTagName('totalRooms')[0].firstChild.data price = doc.getElementsByTagName('amount')[0].firstChild.data except Exception, e: #print e return None #return zipcode, use, int(year), float(bath), int(bed), int(rooms), price return zipcode, use, int(year), float(bath), int(bed), price def getpricelist(): return filter(None, [getaddressdata(line.strip(), 'Cambridge,MA') for line in open('addresslist.txt')]) if __name__ == '__main__': import drawtree import treepredict housedata = getpricelist() print housedata tree = treepredict.buildtree(housedata, scorefun=treepredict.variance) drawtree.drawtree(tree, 'zillow.png') print "Wrote zillow.png"
#print doc.toxml() gender = doc.getElementsByTagName('gender')[0].firstChild.data age = doc.getElementsByTagName('age')[0].firstChild.data loc = doc.getElementsByTagName('location')[0].firstChild.data region = None for r, s in stateregions.iteritems(): if loc[0:2] in s: region = r if region: result.append((gender, int(age), region, rating)) except: pass return result if __name__ == '__main__': d = getrandomratings(50) # hu, all results are always of the same gender? pdata = getpeopledata(d) print pdata import drawtree import treepredict tree = treepredict.buildtree(pdata, treepredict.variance) treepredict.prune(tree, 0.5) drawtree.drawtree(tree, 'hottree.png') print 'Wrote hottree.png'
return cnt(n.left, pa, l) + cnt(n.right, pa, r) def cnt(n, pa, pcam): if n is None: if uncov(pa): return inf else: return 0 elif uncov(pa) and not pcam: return inf elif uncov(pa) and pcam: return 1 + children(n, False, False, CAM) elif cov(pa) and not pcam: return min(children(n, False, True, UNCOV), children(n, True, False, UNCOV), children(n, True, True, UNCOV)) elif cov(pa) and pcam: return 1 + children(n, False, False, CAM) elif cam(pa) and not pcam: return children(n, False, False, COV) elif cam(pa) and pcam: return 1 + children(n, False, False, CAM) return min(cnt(root, COV, False), cnt(root, COV, True)) # main root = deserialize('[0,null,0,null,0,0,0]') drawtree(root) print(Solution().minCameraCover(root))