Array design question
Paul Rubin
http
Thu May 29 06:19:15 EDT 2003
Peter Slizik <peter.slizik at pobox.sk> writes:
> Simple PHP code
>
> a[1] = 'aaa'
> a[2] = 'bbb'
> a[3] = 'ccc'
>
> will in Python read
>
> a.append('aaa')
> a.append('bbb')
> a.append('ccc')
Just use a dictionary:
a = {}
a[1] = 'aaa'
a[2] = 'bbb'
a[3] = 'ccc'
> Simple PHP code
>
> while( !eof() ) {
> line = readline();
> (number, text) = split(line);
> array[number] = text;
> }
>
> seems untranslatable into Python.
a = {}
for line in file:
number, text = line.split(' ')
a[number] = text
More information about the Python-list
mailing list