Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,931 questions

51,868 answers

573 users

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

3 Answers

0 votes
lst = [[1], [4, 5, 6, 7], [8, 9, 10], [0, 17]] 

print(max(len(i) for i in lst)) 
 
 
 
'''
run:
 
4
 
'''

 



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

 



answered Dec 24, 2019 by avibootz
0 votes
def get_max_length_sublist(lst): 
    max_lst = max(lst, key = lambda n: len(n)) 
    return len(max_lst) 


lst = [[1], [4, 5, 6, 7, 2], [1, 2, 3, 7, 8, 9, 10], [0, 17]] 
 
print(get_max_length_sublist(lst)) 
  
  
  
'''
run:
  
7
  
'''

 



answered Dec 24, 2019 by avibootz
...