Approach for improving runtime of Python function

join shbcf.ru