""" More examples of recursion """


def concat_strings(string_list):
    """
    Concatenate all the strings in possibly-nested string_list.

    @param list[str]|str string_list: string(s) to concatenate
    @rtype: str

    >>> list_ = 'cat'
    >>> concat_strings(list_)
    'cat'
    >>> list_ = ['cat', 'dog']
    >>> concat_strings(list_)
    'catdog'
    >>> list_ = ["how", ["now", "brown"], "cow"]
    >>> concat_strings(list_)
    'hownowbrowncow'
    """
    # if this isn't a list, ie. it's an innermost element, don't recurse
    if not isinstance(string_list, list):
        return string_list
    else:
        return ''.join([concat_strings(x) for x in string_list])


def nested_contains(L, value):
    """
    Return whether L, or any nested sub-list of list_ contains value.

    @param list L: list to search
    @param object value: non-list value to search for
    @rtype: bool

    >>> list_ = ["how", ["now", "brown"], 1]
    >>> nested_contains(list_, "brown")
    True
    >>> nested_contains([], 5)
    False
    >>> nested_contains([5], 5)
    True
    """

    # since nested_contains returns a bool
    # and the == evaluates to a bool
    # this is a list of bools
    return any([nested_contains(x, value)
                    if isinstance(x, list)
                    else x == value
                    for x in L])

if __name__ == '__main__':
    import doctest
    doctest.testmod()
