Not a one-line, but cleaner generator solution, also avoiding the conversion int-> string-> int:
def asDigits(n): while n: n,d = divmod(n,10) yield d print sum(asDigits(2**1000))
Gives 1366.
Interestingly, the sum of the digits in 2 ** 10000 is 13561, the digits of which are the same value as 1366.
Of course, if expressed in binary terms, the sum of the digits in 2 ** 1000 is 1. (I even did it in my head!)
Paulmcg
source share