No problem with Python 2.7.3 on a MacBookPro with 2GB memory and a light load
of other programs. Could it be dependent on how much memory you have
available?
There might be slight differences in the memory consumption in computing the
two different forms. I would guess the second form might take less memory
because it allocates exactly what it needs, not some larger amount based on a
dynamic allocation algorithm for expanding lists.
>________________________________
> From: Litvin <[email protected]>
>To: [email protected]
>Sent: Saturday, April 21, 2012 1:50 PM
>Subject: [Edu-sig] MemoryError?
>
>
>Can someone please explain why
>
>n = 50000000
>lst = [i for i in range(n)] # or xrange(n) in Python 2
>
>crashes with MemoryError on a 32-bit system, while
>
>n = 50000000
>lst = n*[0]
>for i in range(n): # or xrange(n) in Python 2
> lst[i] = i
>
>works?
>
>Thanks,
>
>Gary Litvin
>www.skylit.com
>
>
>_______________________________________________
>Edu-sig mailing list
>[email protected]
>http://mail.python.org/mailman/listinfo/edu-sig
>
>
>
_______________________________________________
Edu-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/edu-sig