problem 1 better solution python