Simplifying problem 1 using list comprehension