# Revision history [back]

You don't need Sage for that, you can use pure Python. Here is a solution with list comprehensions:

L = [[1,2,3,4],[1,2],[1,4,5,6],[9,10,12,8],[7,3],[4,5,6]]
lengths = list(len(l) for l in L)

maxLength = max( len(l) for l in L )
print(maxLength)

listWithMaxLength = list(l for l in L if len(l) == maxLength)
print(listWithMaxLength)


First we create the list lengths with the lengths of the individual lists. Then we can simply get the maximum length as the maximum of that list. Now we create a new list listWithMaxLength where we put all the lists from L in which have this maximum length. I'm sure there are faster methods to do that but for reasonable inputs this should work absolutely fine.

You don't need Sage for that, you can use pure Python. Here is a solution with list comprehensions:

L = [[1,2,3,4],[1,2],[1,4,5,6],[9,10,12,8],[7,3],[4,5,6]]
lengths = list(len(l) for l in L)

maxLength = max( len(l) for l in L )
print(maxLength)

listWithMaxLength = list(l for l in L if len(l) == maxLength)
print(listWithMaxLength)


First we create the list lengths with the lengths of the individual lists. Then we can simply get the maximum length as the maximum of that list. Now we create a new list listWithMaxLength where we put all the lists from L in which have this maximum length. length (for this you can also use the method filter from python). I'm sure there are faster methods to do that but for reasonable inputs this should work absolutely fine.