How to get the max length sublist in a nested list with Python

2 Answers

0 votes
lst = [[1], [4, 5, 6, 7, 2], [8, 9, 10], [0, 17]] 
 
print(max(lst, key = len)) 
  
  
  
'''
run:
  
[4, 5, 6, 7, 2]
  
'''

 



answered Dec 24, 2019 by avibootz
0 votes
lst = [[1], [4, 5, 6, 7, 2], [1, 2, 3, 8, 9, 10], [0, 17]] 
 
print(max(lst, key = lambda n: len(n))) 
  
  
  
'''
run:
  
[1, 2, 3, 8, 9, 10]
  
'''

 



answered Dec 24, 2019 by avibootz
...