My first stumbling block with Python

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Aug 22 09:38:42 EDT 2002


"Mr. Neutron" <nicktsocanos at charter.net> wrote in 
news:pan.2002.08.22.09.12.51.873478.1758 at charter.net:

> Now the question is, are there any easier or better ways to get a two
> dimensional array of tuples in Python
> 
> Something like 
> 
>           MyArray[X][Y] = (tuple)

Initialise a list of lists:

    MyArray = [ [None] * Rows for i in range(Cols) ]
    MyArray[c][r] = "whatever you want"

If your data is sparse, then an alternative is:

    MyArray = {}
    MyArray[X, Y] = "whatever"

although this makes it hard to iterate over the elements in order.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list