This is a revisit to a question already asked here about a year and a half ago.
Project Euler's Problem 40 involves generating the sequence of digits that appear in the natural numbers, all concatenated together (
123456789101112131415161718192021…). As part of the solution, I wrote this:
def counting_digits(): for number in count(1): for digit in str(number): yield digit
After finishing the solution, I tried this:
def counting_digits(): return (digit for number in count(1) for digit in str(number))
- 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.