Question #102603

Write a python function that can finds the following from a given list of strings.

How many word start with “Help”?

How many words contain “lp” in it?

Print the largest string?

Print three smallest strings?

Print a string which contains ‘lo’ and has length of atleast 10

Expert's answer

def that_can_find_the_following(strings):
    help = 0
    lp = 0
    largest = ''
    smallest = strings[0]
    three_smallest = []
    lo = ''
    for i in strings:
        if i[:4] == 'Help':
            help += 1
        if 'lp' in i:
            lp += 1
        if len(i) > len(largest):
            largest = i
        if 'lo' in i and len(lo) > 9:
            lo = i
    for x in range(3):
        for z in strings:
            if len(z) < len(smallest):
                smallest = z
                strings.pop(z)
                three_smallest.append(smallest)
                smallest = strings[0]
    print('Help ' + help)
    print('lp ' + lp)
    print('largest ' + largest)
    print(' 3 smallest ' + three_smallest[0] + three_smallest[1] + three_smallest[2])
    print('lo '+lo)
LATEST TUTORIALS
APPROVED BY CLIENTS