44.1k views
1 vote
The function below takes one parameter: a list of strings (string_list). Complete the function to return a new list containing only the strings from the original list that are less than 20 characters long. For this question, you'll first want to create an empty list. Then, you'll want to visit every element of the original list checking to see if it is short. You'll append the short strings to your new list. Finally, return the new list.

User JMSilla
by
4.7k points

1 Answer

2 votes

Answer:

def short_strings(string_list):

short_list = []

for s in string_list:

if len(s) < 20:

short_list.append(s)

return short_list

Step-by-step explanation:

* The code is in Python.

- Create a function called short_strings that takes one parameter, string_list

- Create an empty list called short_list to hold the strings that are less than 20 characters

- Initialize a for loop that iterates through the string_list. Check if there are strings that are less 20 characters in the string_list. If found, put them in the short_list

- Return the short_list

User Amzath
by
5.7k points