<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def evaluate_hostgroup_expression(expr, hosts, hostgroups, look_in='hostgroups'):
 """ Evaluate hostgroup expression :param expr: an expression :type expr: str :param hosts: hosts object (all hosts) :type hosts: alignak.objects.host.Hosts :param hostgroups: hostgroups object (all hostgroups) :type hostgroups: alignak.objects.hostgroup.Hostgroups :param look_in: item name where search :type look_in: str :return: return list of hostgroups :rtype: list """

        # Maybe exp is a list, like numerous hostgroups entries in a service, link them
        if isinstance(expr, list):
            expr = '|'.join(expr)
        if look_in == 'hostgroups':
            node = ComplexExpressionFactory(look_in, hostgroups, hosts)
        else:  # templates
            node = ComplexExpressionFactory(look_in, hosts, hosts)
        expr_tree = node.eval_cor_pattern(expr)

        set_res = expr_tree.resolve_elements()

        # HOOK DBG
        return list(set_res)