Answer to Question #102734 in Python for Rawan almousa

Question #102734
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
1
Expert's answer
2020-02-11T05:39:23-0500

Answer:

def func(list):
    iterator1 = 0
    iterator2 = 0
    iterator3 = 0
    largest_str = "..."
    Largest_str = "..."
    
    for i in list:
        if (len(i) >= 4 and i.find('Help') == 0):
            iterator1 += 1
        if (len(i) >= 2 and i.find('lp') != -1):
            iterator2 += 1
        if (len(i) > iterator3):
            iterator3 = len(i)
            largest_str = i
        if (len(i) >= 10 and i.find('io') != -1):
            Largest_str = i
    
    length = 10e5
    a = ""
    for i in list:
        if (len(i) < length):
            length = len(i)
            a = i
    list.remove(a)
    length = 10e5
    b = ""
    for i in list:
        if (len(i) < length):
            length = len(i)
            b = i
    list.remove(b)
    length = 10e5
    c = ""
    for i in list:
        if (len(i) < length):
            length = len(i)
            c = i
    list.remove(c)
        
        
    
    print("Number of words, which are begin with \"Help\": " + str(iterator1))
    print("Number of words, which are contain \"lp\": " + str(iterator2))
    print("Largest string in the list: \"" + largest_str +'\"')
    print("Three smallest elements of the list: \"" + a + '\", \"' + b + '\", \"' + c + '\"')
    print("The string(length <= 10), which contain \"io\": \"" + Largest_str + "\"")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS