Use a comprehension to replace repetitive code