Creating a matrix?
Peter Maas
peter.maas at mplusr.de
Fri Apr 2 10:57:54 EST 2004
Peter Hansen wrote:
> >>> matrix[1][2] = '1'
> >>> matrix
> [['0', '0', '1', '0'], ['0', '0', '1', '0'], ['0', '0', '1', '0'], ['0',
> '0', '1
> ', '0']]
>
> Notice that each of the inner lists contains four seperate references
> to the string '0', but the outer repetition simply copies the inner
> list four times, resulting in four references to the same inner list!
> Changing any one element affects the same entry in each of the other
> three lists...
Sorry:
matrix = [['0']*N for i in range(N)]
Mit freundlichen Gruessen,
Peter Maas
--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail peter.maas at mplusr.de
-------------------------------------------------------------------
More information about the Python-list
mailing list