I am trying to find the longest word in a non-empty list. My function is supposed to return the longest word. If elements are of equal length in the list, I am trying to sort out the longest in terms of Unicode sorting. For example, I am trying to return the following:
>>> highest_word(['a', 'cat', 'sat'])
'sat'
>>> highest_word(['saturation', 'of', 'colour'])
'saturation'
>>> highest_word(['samIam'])
'samIam'
So far I can get the first one to work, this is my code so far:
def highest_word(wordlist):
longestWord = ""
max_len = 0
for word in wordlist:
if len(word) > max_len:
longestWord = len(word)
longestWord = word
return longestWord
Any sort of help would be greatly appreciated.