On 5 November 2012 06:27, Demian Brecht <demianbre...@gmail.com> wrote:
> >>> a = [None] * 4 > >>> a[0] = 'a' > >>> a > ['a', None, None, None] > > >>> m = [[None] * 4] * 4 > >>> m[0][0] = 'm' > >>> m > [['m', None, None, None], ['m', None, None, None], ['m', None, None, > None], ['m', None, None, None]] > > Is this expected behaviour and if so, why? In my mind either result makes > sense, but the inconsistency is what throws me off. z = [[None] * 4] goes to z = [x, x, x, x] where x = [y] where y = None AND THEN z[0] = 2 means z = [p, x, x, x] where p = 2 AND z[1][0] = 3 means x = [q] where q = 3 hence z = [2, [3], [3], [3]]
-- http://mail.python.org/mailman/listinfo/python-list