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 :: how to install drivers for selenium python 
Python :: what to do in python when you get pygame.Surface object is not callable 
Python :: return count of unique values pandas 
Python :: linux ubuntu install python 3.7 
Python :: folium anaconda 
Python :: Update all packages using pip on Windows 
Python :: python underscore variable 
Python :: pip code for pytube 
Python :: python all possible combinations of multiple lists 
Python :: python youtube downloader mp3 
Python :: discord.py add role on member join 
Python :: make y axis start at 0 python 
Python :: pd read csv unname 
Python :: pandas replace nonetype with empty string 
Python :: python how to read a xlsx file 
Python :: matplotlib x label rotation 
Python :: how to read the first line in a file python 
Python :: tk table python 
Python :: unlimited arguments python 
Python :: how to lowercase list in python 
Python :: pytorch load model 
Python :: extract float from string python 
Python :: python roman to integer 
Python :: remove web linnks from string python 
Python :: how to receive password using tkinter entry 
Python :: getting dummies and input them to pandas dataframe 
Python :: python how to make an array of ones 
Python :: python split range equally 
Python :: remove non-alphabetic pandas python 
Python :: how will you print space and stay on the same line in python 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =