def max_length(obj: Union[int, List]) -> int:
"""Return the maximum length of any list in nested list
<obj>.
The *maximum length* of a nested list is defined as:
1. 0, if <obj> is a number.
2. The maximum of len(obj) and the lengths of the nested lists
contained
in <obj>, if <obj> is a list.
>>> max_length(17)
0
>>> max_length([1, 2, [1, 2], 4])
4
>>> max_length([1, 2, [1, 2, [3], 4, 5], 4])
5
"""
pass
def max_length(accept)->int:
currentMaxLength=0;
if(isinstance(accept, int)):
return 0;
else :
subListsLength = 0;
currentMaxLength = len(accept);
for lists in accept:
if(not isinstance(lists, int)):
subListsLength = len(lists)
if(subListsLength>currentMaxLength):
currentMaxLength = subListsLength
return currentMaxLength
return 0
print(max_length([5,4,[1,2,3,4,5],1]))
Get Answers For Free
Most questions answered within 1 hours.