def find_selected(nodes):
 for node in nodes:
  if hasattr(node, 'selected'):
   return node
  elif hasattr(node, 'ancestor'):
   result = find_selected(node.children)
   if result:
    return result

def find_selected ( nodes ) : for node in nodes : if hasattr ( node , 'selected' ) : return node elif hasattr ( node , 'ancestor' ) : result = find_selected ( node . children ) if result : return result
finds a selected nav_extender node .