translate part of js to python code