Your edit is probably fine, but one thing to note is that you made extensive changes in the presented code, and in the process you fixed the code's indentation.
Python being python, that is a change that could alter the "intent" of the author. Not saying that is was, but that suggested edits that alter code need to be mindful of these things, as well as reviewers.
Still, your edit happening on an answer... fixing the indentation was probably the right thing to do, in my opinion.
Going beyond that, do try to use more descriptive edit comments.
What you did with that piece of code went beyond "formatting", since indentation is significant in python. If you are fixing something, take the time to describe it properly so the reviewers know what were you on about.
One word summaries are not useful to anyone, and on suggested edits that modify a post's code it is particularly important to be as descriptive as possible.
In this case, were I to suggest such an edit, I'd write something along the lines of:
"Fixed code indentation. Code was functionally ok but indentation was probably mangled on pasting, which made the code impossible to execute. Also removed unnecessary formatting in the last paragraph."
Now a reviewer can read the suggested edit description and find the corresponding changes in the edit. No need for the reviewer to second-guess you, and more likely to be approved if it's a good edit.