def _mostfunc(lhs, func, X=None):
 fterms = [tmp for tmp in lhs.atoms(func) if ((not X) or (X.is_Symbol and (X in tmp.free_symbols)) or ((not X.is_Symbol) and tmp.has(X)))]
 if (len(fterms) == 1):
  return fterms[0]
 elif fterms:
  return max(list(ordered(fterms)), key=(lambda x: x.count(func)))
 return None

def _mostfunc ( lhs , func , X = None ) : fterms = [ tmp for tmp in lhs . atoms ( func ) if ( ( not X ) or ( X . is_Symbol and ( X in tmp . free_symbols ) ) or ( ( not X . is_Symbol ) and tmp . has ( X ) ) ) ] if ( len ( fterms ) == 1 ) : return fterms [ 0 ] elif fterms : return max ( list ( ordered ( fterms ) ) , key = ( lambda x : x . count ( func ) ) ) return None
returns the term in lhs which contains the most of the func-type things e .