You need to define/decide what you
mean by "quality", it's a very subjective term.
For me code has "quality" if it works and is easy to read (and therefore easier to maintain).
The technique you want to research is called "refactoring"
Here are a couple of blogs that give some tips on how to go about that
Quick Python Refactoring Tips | Python Engineer
Quick Python Refactoring Tips (Part 2) | Python Engineer
There are many other articles available.
Just be careful to not introduce bugs or change code behaviours while you refactor, and learn when enough is enough - i.e. when to stop