Multidimensional arrays - how?

rzed Dick.Zantow at lexisnexis.com
Fri May 3 08:38:24 EDT 2002


"Jaros³aw Zabie³³o" <webmaster at apologetyka.com.pl (delete .PL)> wrote in
message news:6vv4du8mu1hj59k7g0uq58r24mp74g02hu at 4ax.com...
> How to create multidimmensional arrays in Python? I tried:
>
> x = []
>
> book, chapter, para = 0,0,0
> x[book][chapter][para] = 'text0'
>
> book, chapter, para = 0,0,1
> x[book][chapter][para] = 'text1'
>
> This code does not work in Python :-( but (with slightly changings)
> works in PHP, C, C++ or Pascal).
>

Does this give you what you want? It's not a multidimensional array, but
do you need it?:
>>> x = {}
>>> book,chapter,para=0,0,0
>>> x[book,chapter,para] = 'text0'
>>> book,chapter,para=0,0,1
>>> x[book,chapter,para] = 'text1'
>>> x[0,0,1]
'text1'
>>> x[0,0,0]
'text0'





More information about the Python-list mailing list