Replace for loop with comprehension