Optimizing code with PyCharm