Practice practice and some more practice. Make sure to make time for some more practice in between. You won't even realize when you have started writing code like this...
The most important thing here is the list comprehension (sum(int(x)) for x in str(value)
It is nothing but a for loop, you will write hundreds of for loops until it just clicks that what you're trying to do is this essential form, and then it comes naturally.
I am still new to python but I wonder how does someone think about these one liner clean code, does it come after few iterations or they pop up just like that :)
Practice practice and some more practice. Make sure to make time for some more practice in between. You won't even realize when you have started writing code like this...
The most important thing here is the list comprehension (sum(int(x)) for x in str(value)
It is nothing but a for loop, you will write hundreds of for loops until it just clicks that what you're trying to do is this essential form, and then it comes naturally.
the more you see it the more obvious it gets
I am still new to python but I wonder how does someone think about these one liner clean code, does it come after few iterations or they pop up just like that :)