python - How do i print the longest and shortest words out of a given set of words? -
what want write code detect longest , shortest words given in list. tried write code find longest word using number of characters failed bad...i'm wondering if there simple function or line i'm missing.
mywords=['how','no','because','sheep','mahogany'] n = len(mywords) a=0 while < n: print(( len( list(mywords[a])))) += 1 if > n: break though print of number of characters of each word cant figure out how proceed.
ps : id know how create list values obtained result above function
you can use max, , min.
>>> max(mywords, key=len) 'mahogany' >>> min(mywords, key=len) 'no'
Comments
Post a Comment