how to find the longest string in a list in python

40

how to find the longest string in a list in python -

a_list = ["a_string", "the_longest_string", "string"]
longest_string = max(a_list, key=len)
print(longest_string)

python longest list in list -

def longest(list1):
    longest_list = max(len(elem) for elem in list1)
    return longest_list

Comments

Submit
0 Comments