Codility Demo Test Solution Python