It can, but list comprehensions/generator expressions are the exact sort of thing that should be used here. Depending on what you want to do in your if
block, you could use some form of map
or reduce
, but list comprehensions and generator expressions are likely the best way to do it.