Answers for "find shortest string in list python"

1

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'
Posted by: Guest on May-01-2021
0

python return min length of list

a = [[1,0,1,2,1,1,1,3111111], [31,1,4,51,1,1,1], [1,1,6,7,8]]

print min(a, key=len)
# [1, 1, 6, 7, 8]

print len(min(a, key=len))
# 5

print min(map(len, a))
# 5
Posted by: Guest on April-28-2020
0

python min length list of strings

strings = ["some", "example", "words", "that", "i", "am", "fond", "of"]
print min(strings, key=len) 
# prints "i"
Posted by: Guest on February-11-2020
0

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
Posted by: Guest on April-24-2021

Code answers related to "find shortest string in list python"

Browse Popular Code Answers by Language