How to optimize the code and reduce memory usage Python

join shbcf.ru