Some comments, yes, but none of which I’d suggest you act on
Entirely cosmetic, 4 spaces are generally preferred over tabs for python. But codecademy’s editor isn’t entirely well behaved so if tabs are working for you just keep doing that.
I’d switch places on the if/else parts just to turn
==. “not” is more difficult to think about. Again, entirely cosmetic.
And then I’d not make the function at all, because str’s replace method already does all of this. However, for the sake of the exercise one has to draw the line somewhere…
str’s split already splits on whitespace. Splitting on space is more specific, I’d still leave it to default…It already does the right thing
+= with strings would be fine for spaces, it just takes a different action at either the first or last iteration. Storing the words in a list is still better though, because strings don’t support appending - list is the right data structure to use. (And it obviously avoids the special case for the first or last iteration)