Below are what I have generalized after lots of writting and testing Python code.

  1. If your written code is difficult to test, it’s bad code, refactor it!

  2. If your written code has serious performance issue, refactor it!

  3. If the above two doesn’t apply, then your code has a better chance of being bug-free (No guarantee though) and performing well. It’s nice code, so have a cup of tea/coffee and relax.