The primary issue I have with the assignments is line 18 and 19, they are already captured by the regex \s+.  This means this code is possibly doing the same thing 3 time, which over a large html file adds up. Whether the final return value or return re.sub is appropriate, I will defer to @cyberdelia .