brain stuck. whats occurring here?
Robin Becker
robin at reportlab.com
Thu Feb 7 13:01:36 EST 2008
Matthew_WARREN at bnpparibas.com wrote:
> Hallo,
>
> I'm after
>
> [[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]]]
>
> (NxN 'grid', 5x5 in that example, and while typing this up i figured out
> how to get it, but I'm still not sure what _was_ happening)
>
>
> I'm trying
>
>>>>> a=[]
>>>> row=[ [] for n in range(0,10) ]
>>>> a.extend(row[:])
>>>> a
> [[], [], [], [], [], [], [], [], [], []]
>>>> a[0].extend(row[:])
>>>> a
> [[[...], [], [], [], [], [], [], [], [], []], [], [], [], [], [], [], [],
> [], []]
>
>
> why isnt that last a
>
> [[[...]],[],[],[],[],[],[],[],[],[]]
>
>
> Puzzled :)
>
> Matt.
> --
........
To get an n by m grid I would use
[[[] for i in xrange(m)] for j in xrange(n)]
--
Robin Becker
More information about the Python-list
mailing list