Source: https://www.cvl.isy.liu.se/education/undergraduate/tsbb15/computer-exercises/lektion_python.pdf