replace for loop with a list comprehension