473,395 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

access python multi dimentional array

To make the q simple: i want to access inner array elements by the names of the inner arrays. thanks

here's a more complex explanation:

I have those arrays:

animatorsNames = ["jun","sonny","xandy"]

jun = ["rifai","hassan","ali"]
sonny = ["omar", "khaled"]
xandy = ["heba","zuhdi","lutfi"]

animators = [jun,sonny,xandy]

I want to go over the array with loops like this:

for scene in animatorsNames :
for animator in scene:
do something


th problem is that i want to access the array elements through the names of those inner arrays, jun, sunny, etc. but when i go over the second loops, it treats the animator variable as a variable, rather than an array. which is the right thing for it to do. but how would i be able to achieve it to go over those variables as if they are the inner arrays.

I hope it was clear, any help is appreciated.

thanks a lot ppl :D
May 11 '08 #1
2 1705
woooee
43
You have to use a dictionary of lists for that if I read the question correctly.
Expand|Select|Wrap|Line Numbers
  1. names_dic = {}
  2. names_dic["jun"] = ["rifai","hassan","ali"] 
  3. names_dic["sonny"] = ["omar", "khaled"] 
  4. names_dic["xandy"] = ["heba","zuhdi","lutfi"]
  5.  
  6. print 'list associated with "sonny" is ', names_dic["sonny"]
  7.  
  8. ##
  9. animators = ["jun","sonny","xandy"]
  10. for name in animators:
  11.    if name in names_dic:
  12.       for list_name in names_dic[name]:
  13.          print list_name, "is accessed via", name
  14.    else:
  15.       print name, "is not in the dictionary"
  16.    print
  17.  
  18. ##   to print all in alphabetical order, sort the keys 
  19. keys_list = names_dic.keys()
  20. keys_list.sort()
  21. print keys_list
May 11 '08 #2
didnt know dictionaries cld have more than a single definition! thanks a lot mate thats exactly what i want

Cheers :D
May 11 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Cedric Baelemans | last post by:
Hi, I try to store a two-dimentional array in a session variable. When I do the same with a one-dimentional array, it works fine, but with a two-dimentional array it fails. Is this not possible?...
1
by: Matt | last post by:
I am trying to create a 2 dimentional array with a uniqId value and another Array.This is the code I am trying but it is not working. Please help me out gurus.. MainArray = new Array(0,0); ...
2
by: Abby | last post by:
From my code below, it will open a file specified in argv, then read line by line and store each line in an array call IPTemp. After reading until EOF, it will return array IPTemp to main, which...
1
by: rkmoray | last post by:
I have created a Multi Dimentional array, but having problems filling it. int mCount=0; mCount=ds.Tables.Rows.Count; string arrayppsa = new string ; DataTable myDataTable=ds.Tables;...
0
by: rkmoray | last post by:
I have created a Multi Dimentional array, but having problems filling it. int mCount=0; mCount=ds.Tables.Rows.Count; string arrayppsa = new string ; DataTable myDataTable=ds.Tables;...
0
by: Max M. Power | last post by:
I'm getting an InvalidOperationException calling Invoke with a method parameter object array that contains a two dimentional string array. More stack trace output below: // Create two...
2
by: adamizer | last post by:
okay i try to compile this simple code in Dev C++ and i get some serious errorage #include <iostream> using namespace std; int main() { char array = {{'a','b','c','d','e'},
9
by: Srinu | last post by:
Hi All, We know the following facts, 1. A two dimentional arrays in C is stored similar to a single dimentional array. 2. * is the dereference operator that gives value at address denoted by...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.