Python solution for number 6