This is a revisit to a question already asked here about a year and a half ago. While solving Project Euler's Problem 40 I wrote this:def counting_digits():    for number in count(1):        for digit in str(number):            yield digitAfter finishing the solution, I tried this:def counting_digits():    return (digit for number in count(1) for digit in str(number))My questions:In the face of Python 3, Which solution is more pythonic?As someone who just wants to understand the code. Which is easier/clearer to read?If you haven't read the statement for Project Euler's Problem 40, Which version lets you better know what the function does?Performance is not part of the question: pythonism and understandability is the issue.As @ninjagecko explains in his answer, the yield solution may be more readable because of the double for within the scoping rules of Python in the single-line expression.Others have pointed out that the yield version may be easier to understand for programmers coming from other programming languages, even the ones that don't support such construct. I my self note that in functional languages like Haskell and OCAML, expressions are built (using let) more like in the first version.
Generator expressions or yield generators?
python;generator
The one where you return a generator is easier to read were it the case that there was only one for. Also, as OP pointed out, the associativity of nested for loops is not what you'd expect in Python.The top one may be slightly easier to read for some people; it would be MUCH easier to read if there were comments or if the variables were semantically named, and the indented structure allows for comments much better. With semantically-named variables, the first version is easier to read; I'd only use single-letter variable names as the pattern in list comprehensions.