How to get the length of longest string in a list of strings with Python

2 Answers

0 votes
lst = ['python', 'php', 'java', 'c', 'c++', 'javascript', 'nodejs']
   
result = max(len(e) for e in lst) 
 
print(result)  
 
          
       
'''
run:
 
10
       
'''

 



answered Apr 25, 2020 by avibootz
0 votes
lst = ['python', 'php', 'java', 'c', 'c++', 'javascript', 'nodejs']
   
result = len(max(lst, key = len)) 
 
print(result)  
 
          
       
'''
run:
 
10
       
'''

 



answered Apr 25, 2020 by avibootz
...