Need help initializing a list or tuple.

Fredrik Lundh fredrik at pythonware.com
Mon Mar 6 13:07:10 EST 2006


"KraftDiner" wrote:

> Strange behaviour...
>
> a = [[None] * 256] * 256
> for i in range(0,256):
> for j in range(0,256):
> a[i][j] = i**2
> a = sum(a, [])
> print a[0]
> print a[65535]
>
> Prints:
>
> 65025
> 65025

looks like you missed that the page I pointed you to explained *why*
the a = [[None] * 256] * 256 approach doesn't work...

</F>






More information about the Python-list mailing list