way to calculate 2**1000 without expanding it?
Ian Kelly
ian.g.kelly at gmail.com
Fri Sep 16 23:11:44 EDT 2011
On Fri, Sep 16, 2011 at 8:19 PM, Grant Edwards <invalid at invalid.invalid> wrote:
>> Here's another one-liner using a generator instead of map:
>>
>> sum(int(c) for c in str(2**1000))
>
> Just in case you can't spare the 3KB required for the list of integers
> that map creates. :)
>
> In this case it doesn't matter, but it's not hard to find problems
> where the difference between the memory requirements for a generator
> and a map/list-comprehension are significant enough to worry about.
Unless otherwise specified, I generally assume that code on this list
is for Python 3, and map in Python 3 returns an iterator.
Cheers,
Ian
More information about the Python-list
mailing list