from typing import List,Union
"""
some recursive functions on nested lists
"""
def max_depth(obj: object) -> int:
    """
    Return 1 + the maximum depth of obj’s elements if obj is a list.
    Otherwise return 0.
    >>> max_depth(17)
    0
    >>> max_depth([])
    1
    >>> max_depth([1, "two", 3])
    1
    >>> max_depth([1, ["two", 3], 4])
    2
    >>> max_depth([1, [2, ["three", 4], 5], 6])
    3
    """
    if obj == []:
        return 1
    elif isinstance(obj,list):
        return 1+max([max_depth(x) for x in obj])
    else:
        return 0

def rec_max(list_: Union[List,int]) -> int:
    """
    Return the maximum int in nested lists

    lists and sublists must Not be empty or None
    >>> rec_max(17)
    17
    >>> rec_max([-1,0])
    0
    >>> rec_max([1, 2, 3])
    3
    >>> rec_max([1, [5, 3], 4])
    5
    >>> rec_max([1, [2, [9, 4], 5], 6])
    9
    """
    if isinstance(list_,list):
        return max([rec_max(x) for x in list_])
    else:
        return list_

def concat_strings(string_list: Union[List,str]) -> str:
    """
    Concatenate all the strings in possibly-nested string_list.
    >>> list_ = ["how", ["now", "brown1"], "cow1"]
    >>> concat_strings(list_)
    'hownowbrown1cow1'
    """
    return "".join([concat_strings(x) if isinstance(x,list)
                    else x
                    for x in string_list])
    # if isinstance(string_list,list):
    #     return "".join([concat_strings(x) for x in string_list])
    # else:
    #     return string_list

def flatten(list_: List) -> List:
    """
    Return a flattened list of nested lists

    >>> flatten([1, [5, 3], 4])
    [1, 5, 3, 4]
    """
    # return sum([flatten(x) if isinstance(x,list)
    #         else [x]
    #         for x in list_],[])
    if isinstance(list_,list):
        return sum([flatten(x) for x in list_],[])
    else:
        return [list_]

def nested_contains(list_: list, value: object) -> bool:
    """
    Return whether list_, or any nested sub-list of list_ contains value.
    >>> list_ = ["how", "now", "brown", 1]
    >>> nested_contains(list_, "now")
    True
    >>> nested_contains(list_, 1)
    True
    >>> nested_contains(list_, 3)
    False
    >>> list_ = ["how", ["now", "brown"], 1]
    >>> nested_contains(list_, "now")
    True
    >>> nested_contains([], 5)
    False
    >>> nested_contains([5], 5)
    True
    """
    # check out Python built-in any
    if isinstance(list_,list):
        return any([nested_contains(x,value) for x in list_])
    else:
        return value == list_


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