FWIW, overly long iterator comprehensions, or unwieldy chains of them, are common in Python, but a local generator function is much cleaner most of the time in my experience. The difference is slight here but the rule of thumb never goes wrong for me. Splitting the logic out into a generator function tends to make the flow more readable, and it becomes easier to make changes to the logic or add intermediate filters or variables.