avoid nested for loops in list comprehensions