<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def best_parent( self, node, tree_type=None ):
 """Choose the best parent for a given node"""

        parents = self.parents(node)
        selected_parent = None
        if node['type'] == 'type':
            module = ".".join( node['name'].split( '.' )[:-1] )
            if module:
                for mod in parents:
                    if mod['type'] == 'module' and mod['name'] == module:
                        selected_parent = mod 
        if parents and selected_parent is None:
            parents.sort( key = lambda x: self.value(node, x) )
            return parents[-1]
        return selected_parent