2d arrays

Josiah Carlson jcarlson at uci.edu
Tue Nov 2 12:05:14 EST 2004


Ajay <abra9823 at mail.usyd.edu.au> wrote:
> 
> hi!
> 
> i am trying to do something as follows:
> i have a set of id's. These are from 4-10.
> I also have a set of users. Users have values for some of these id's
> thus, userA could have userA(4)=7, userA(6)=4 and userB may only have
> userB(7)=3
> 
> what i am trying to do is to make this into a 2d array
> 
> id's/users 4 5 6 7 8 9 10
> userA      7   4
> userB            3
> userC                3  4

If you don't need to examine columns or rows (random read/write access),
use a dictionary:

2d_a = {}
2d_a[('userA', 4)] = 7
2d_a[('userA', 6)] = 4
2d_a[('userB', 7)] = 3


> and so on. Has anyone done this before? if yes, do you mind sharing how.
> the problem is user information is stored in a db and all id's are stored
> in a table.
> so first of all, i get the entire range of id's from a table.
> i then need to go through all user tables and get their corresponding
> values and do this in an efficient way.

If it is SQL, you can do something like this...

SELECT member_name, member_id, member_val FROM member_table WHERE
deleted <> 'f'

etc.


 - Josiah




More information about the Python-list mailing list