Fix the bug: the list shrinks while you walk it
Every deploy runs the folder through clean_files first. Editors leave .bak
copies of whatever you were last editing, and a web server does not know what a
.bak is - it just hands the raw file to anyone who asks for it by name. So the
script strips them before upload, and it has been stripping them for a year
without complaint.
Last Friday styles.css.bak showed up on the live site.
Nothing crashed. No traceback, no warning, no log line. clean_files was handed
six filenames, it removed two of the three backups, and it returned a list that
looks perfectly reasonable until you count what is in it. Run it and read the
output against the input - the survivor is sitting right there.
The loop is fine. The list is fine. What breaks is doing both at once.
Your task: fix clean_files(files) so it returns every filename that does
not end in .bak - all three backups gone, every other file kept, in order.
You'll practice:
Reading a returned list as a claim, and counting whether the claim holds
Spotting a loop whose list is being shortened underneath it
Show a hint
Show solution
Previous Next