[Python-3000] Best Practices essays

Edward C. Jones edcjones at comcast.net
Fri Mar 24 17:12:55 CET 2006


Adam DePrince wrote:

> Now, as for your example m * [ n * [0]], I would exclude it from a best
> practices document.  If  your goal is to create a two dimensional array
> of numbers, it doesn't work.  The first part, n* [0] is right, you are
> creating a list of n zeros, and when you say l[x]=y you are replacing
> that element.  
> 
> The second part, m *, is wrong.  You are creating a list of m references
> to the same list of n zeros.  

I know its wrong. It was a mistake I made several times when I was 
earning Python. The m * [ n * [0]] problem is a dark corner of Python 
that exists because Python variables are really pointers. Unfortunately, 
this dark corner is visible to newbies. Which is why it needs to be 
mentioned.


More information about the Python-3000 mailing list