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
2 1705
You have to use a dictionary of lists for that if I read the question correctly. - names_dic = {}
-
names_dic["jun"] = ["rifai","hassan","ali"]
-
names_dic["sonny"] = ["omar", "khaled"]
-
names_dic["xandy"] = ["heba","zuhdi","lutfi"]
-
-
print 'list associated with "sonny" is ', names_dic["sonny"]
-
-
##
-
animators = ["jun","sonny","xandy"]
-
for name in animators:
-
if name in names_dic:
-
for list_name in names_dic[name]:
-
print list_name, "is accessed via", name
-
else:
-
print name, "is not in the dictionary"
-
print
-
-
## to print all in alphabetical order, sort the keys
-
keys_list = names_dic.keys()
-
keys_list.sort()
-
print keys_list
didnt know dictionaries cld have more than a single definition! thanks a lot mate thats exactly what i want
Cheers :D
Sign in to post your reply or Sign up for a free account.
Similar topics
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?...
|
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);
...
|
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...
|
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;...
|
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;...
|
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...
|
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'},
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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,...
| |