I have to find the longest list inside a list of lists.
For example:
longest([1,2,3]) returns 3
longest([[[1,2,3]]]) also returns 3 (inner list is 3)
longest([[], [3,[4,5],[2,3,4,5,3,3], [7], 5, [1,2,3], [3,4]], [1,2,3,4,5]]) returns 7 (list [3,[4,5],[2,3,4,5,3,3], [7], 5, [1,2,3], [3,4]] contains 7 elements)
Right now I have this code, but it doesn't do the trick with the first two examples.
def longest(list1):
longest_list = max(len(elem) for elem in list1)
return longest_list
Maybe recursion will help?