Simplified code by using a list comprehension