python--获取节点
#usr/bin/python #-*-coding:utf-8-*- class Tree : childToParent= None parentToChildren= None #获取父节点 def add ( self ,parent,child): if self .childToParent is None : self .childToParent={child:parent} else : self .childToParent[child]=parent if self .parentToChildren is None : self .parentToChildren={parent:[]} children= self .parentToChildren.get(parent,[]) if len (children)== 0 : self .parentToChildren[parent]=children children.append(child) # 获取所有子节点 def getParent ( self ,child): return self .childToParent.get(child, "没有父亲的节点" ) def getChildren ( self ,parent): return self .parentToChildren