214k views
3 votes
Write a Python function that returns the sublist of strings in aList that contain fewer than 4 characters. For example, if aList

1 Answer

3 votes

Answer:

def sublist(aList):

new_list = []

for s in aList:

if len(s) < 4:

new_list.append(s)

return new_list

Step-by-step explanation:

Create a function called sublist that takes one parameter, aList

Inside the function, create a new_list that will hold the strings which are less than 4 characters. Create a for loop that iterates through the aList. If a string in aList is less than 4 characters, add it to the new_list. When the loop is done, return the new_list

User Marslo
by
5.5k points