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 1719
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? Is there something special I have to
take into account?
Any help is welcome
Cedric
|
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
|
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>
|
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) {
|
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) {
| |
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";
|
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 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
|
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,...
|
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...
|
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...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |