[ [ [] * y for y in range(3) ] * x for x in range(2) ]
David Eppstein
eppstein at ics.uci.edu
Thu Jan 30 01:51:18 EST 2003
In article <2vhh3v4ue9tsn5lgk6lpl7cd92i2s8fgh9 at 4ax.com>,
Chirayu Krishnappa <thephoenix235 at gmx.net> wrote:
> This is whats wrong.
>
> >>> L=[[[]]*3]*2
> >>> L
> [[[], [], []], [[], [], []]]
> >>> L[0][0]=1
> >>> L
> [[1, [], []], [1, [], []]]
Ok, you want a 2x3 table of 6 distinct empty lists...
[[[] for x in range(3)] for y in range(2)]
--
David Eppstein UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/
More information about the Python-list
mailing list