Exercise: Filter sequence of names with for-loop
Iterate over the names tuple and only add the names with less than 5 characters to the list filtered. Hint: You might need to use a conditional statement and the
list.append()
method.names = ('Alice', 'Bob', 'Charlie', 'David', 'Karl')
filtered = []
# add code here...
for
print(filtered)
# expected output: ['Bob', 'Karl']
Python
Setting up Python environment...
Output