473,782 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

access python multi dimentional array

75 New Member
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 1719
woooee
43 New Member
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
askalottaqs
75 New Member
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
2228
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? Is there something special I have to take into account? Any help is welcome Cedric
1
4243
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); tempArray = new Array(); put the values in tempArray
2
3089
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 you'll see a for loop here "for(i=0;i<6;i++)" ... I use 6 here, assuming there's 6 lines in the file I opened. How can I know exactly how many elements in my array? Please help...thanks a lot. #include <stdio.h>
1
3246
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; foreach(DataRow myDataRow in myDataTable.Rows) {
0
1043
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; foreach(DataRow myDataRow in myDataTable.Rows) {
0
2465
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 dimentional array. System::String* tda = new System::String*; tda = "lastName"; tda = "Power"; tda = "firstName"; tda = "Max";
2
1534
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
2467
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 the operand to this operator. i.e *p is the value at address given by p. 3. In case of two dimentional array a, a+1 refers to the second
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.