Gary Herron <gher...@digipen.edu> wrote: >>>> i am writing a program to sum up the digits of a number 2**1000? >>>> Is there a way/formula to do it without expanding it? > > Here's another one-liner using a generator instead of map: > > sum(int(c) for c in str(2**1000))
The OP did not specify the base: >>> bin(2**1000).count('1') 1 Or just: >>> print(1) 1 Stefan Krah -- http://mail.python.org/mailman/listinfo/python-list