# some recursive functions on nested lists

def nested_depth(L):
    """
    Return nested depth of list L.

    Nested depth is:
    0                                   --- if L is a non-list
    1 + maximum nested of elements of L --- if L is a list

    >>> nested_depth(3)
    0
    >>> nested_depth([1, 2, 3])
    1
    >>> nested_depth([1, [2, 3], 4])
    2
    """
    return (1 + 

            # maximum nested depths of elements of L, concatenated with 0
            # to deal with possibility that L is empty
            max([nested_depth(x) for x in L] + [0])

            # 0 if L is a non-list
            if isinstance(L, list) else 0)

def rec_max(L):
    """
    Return the maximum number in L, a possibly nested list of numbers.
    
    >>> rec_max([17, 21, 0])
    21
    >>> rec_max([17, [21, 24], 0])
    24
    """
    return max( # the maximum of
        
        # list of maximums of sublists or plain numbers in L
        [rec_max(x) if isinstance(x, list) else x for x in L])
    
if __name__ == '__main__':
    import doctest
    doctest.testmod()
