Python: Get Longest String in a List

Share Tweet

Here is a quick Python trick you might use in your code.

Assume you have a list of strings and you want to get the longest one in the most efficient way.

>>>l=["aaa", "bb", "c"]
>>>longest_string = max(l, key = len)
>>>longest_string
'aaa'
Share Tweet

Questions?

Please start a discussion down below or send me an email!