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

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -