# some recursive functions on nested lists

def depth(L):
    ''' (list or non-list) -> int

    Return 0 if L is a non-list, or 1 + maximum
    depth of elements of L, a possibly nested
    list of objects

    >>> depth(3)
    0
    >>> depth([])
    1
    >>> depth([1, 2, 3])
    1
    >>> depth([1, [2, 3], 4])
    2
    '''
    # find the bug!
    if isinstance(L, list):
        return 1 + max([depth(x) for x in L])
    else: # L is not a list
        return 0

def rec_max(L):
    ''' (list or int) -> int

    Return L if it's an int, or the maximum int in L,
    a possibly nested list of numbers.

    Assume: L is an int or non-empty list

    >>> rec_max([17, 21, 0])
    21
    >>> rec_max([17, [21, 24], 0])
    24
    '''
    if isinstance(L, list):
        return max([rec_max(x) for x in L])
    else:
        return L

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