Translating the ISLR R code to Python, a mental exercise