Switch loop to list comprehension