Respuesta :
Answer:
def select_short_strings(string_list):
new_list = []
for s in string_list:
if len(s) < 20:
new_list.append(s)
return new_list
lst = ["apple", "I am learning Python and it is fun!", "I love programming, it is easy", "orange"]
print(select_short_strings(lst))
Explanation:
- Create a function called select_short_strings that takes one argument string_list
Inside the function:
- Initialize an empty list to hold the strings that are less than 20
- Inside the loop, check the strings inside string_list has a length that is smaller than 20. If found one, put it to the new_list.
- When the loop is done, return the new_list
- Create a list to check and call the function
Answer:
# the solution function is defined
# it takes a list as parameter
def solution(string_list):
# an empty new list is initialized
new_list = []
# a loop that loop through the splitted_list
# it checks if the length of each string is less than 20
# if it is less than 20
# it is attached to the new list
for each_string in string_list:
if(len(each_string) < 20):
new_list.append(each_string)
# the new list is printed
print(new_list)
# the function is called with a sample list
solution(["The", "player", "determined", "never", "compromised"])
Explanation:
The program is written in Python and it is well commented.