Replace loops with comprehensions when appropriate