associative array

Bernard Czenkusz editor at pythonrag.org
Fri Apr 2 14:01:55 CEST 2010


On Thu, 01 Apr 2010 11:57:11 +0000, Harishankar wrote:

> On Wed, 31 Mar 2010 09:40:30 -0700, Javier Montoya wrote:
> 
>> Dear all,
>> 
>> I'm a newbie in python and would be acknowledge if somebody could shed
>> some light on associative arrays.
>> More precisely, I would like to create a multi-dimensional associative
>> array. I have for example a list of students which are identified
>> uniquely by their student IDs. Additionally, for each student I have
>> some information: FirstName, LastName, etc.
>> 
>> The array would have then the following form: [StudentID] =>
>> [FirstName][LastName][Telephone]...[ ... ]
>> 
>> I would like to be able to access a field directly by using a StudentID
>> [StudentID][FirstName]
>> [StudentID][LastName]
>> 
>> How could I manipulate such an array (create the array, add elements,
>> access data)?
>> 
>> Best wishes
> 
> I know this is not a direct answer, but in your case I would probably
> use a database, because it is the easiest and most standardized way to
> access such types of data. If you don't want something heavyweight, use
> sqlite with in-memory databases/persistent file.
> 
> Look at sqlite3 module in python.

You could also look at the September issue of the Python Rag which has a 
couple of articles on storing a membership class using Shelve, which is 
similar to what you are interested in:
http://www.pythonrag.org/




More information about the Python-list mailing list