Python: Get Longest String in a List
By Güngör Budak
- One minute read - 43 wordsHere 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.
1>>>l=["aaa", "bb", "c"]
2>>>longest_string = max(l, key = len)
3>>>longest_string
4'aaa'