python find longest word in list code example
Example 1: 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)
Example 2: get longest shortest word in list python
words = ["alpha","omega","up","down","over","under","purple","red","blue","green"]
#GET LONGEST WORD
max(words, key=len)
>>> 'purple'
#GET SHORTEST WORD
min(words, key=len)
>>> 'up'