def list_sum(l):
    """
    Return the sum of a list, when the convetiional
    method (like `sum`) it not working.
    For example if you have a list of dolfin functions.

    :param list l: a list of objects
    :returns: The sum of the list. The type depends on
              the type of elemets in the list

    """
    if not isinstance(l, list):
        return l
    out = l[0]
    for item in l[1:]:
        out += item
    return out
