Reformat some for loops as list comprehensions