Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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'
Comment

how to find the shortest word in a list python

def findShortest(lst):
    length = len(lst)
    short = len(lst[0])
    ret = 0
    for x in range(1, length):
        if len(lst[x]) < short:
            short = lst[x]
            ret = x

    return x # return the index of the shortest sentence in the list
Comment

PREVIOUS NEXT
Code Example
Python :: bst in python 
Python :: remove timezone from column pandas 
Python :: bitcoin with python 
Python :: class views django slug 
Python :: opencv write video 
Python :: python is instance numpy arrya 
Python :: Reverse an string Using Reversed 
Python :: value_counts sort by index 
Python :: python seq 
Python :: pyplot histogram labels in center 
Python :: random module 
Python :: py to flag converter online 
Python :: endgame 
Python :: how to set pywal permenent 
Python :: file = Root() path = file.fileDialog() print("PATH = ", path) 
Python :: how to push the element to array in python 
Python :: RuntimeError: cannot open featureclass in python 
Shell :: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation 
Shell :: ubuntu uninstall chrome 
Shell :: postgres stop linux 
Shell :: git stas hauntracked files 
Shell :: upgrade pillow version 
Shell :: flask_wtf install 
Shell :: install nvm with brew 
Shell :: install fira code vscode ubuntu 
Shell :: gyp: No Xcode or CLT version detected! 
Shell :: Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xeu mongod.service" for details. 
Shell :: ubuntu command ram info 
Shell :: git apply .gitignore 
Shell :: how to start psql in linux 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =