cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-464319%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ECr%C3%A9ez%20une%20liste%20pour%20chaque%20%C3%A9l%C3%A9ment%20pr%C3%A9sent%20dans%20une%20liste.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-464319%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EChers%20tous%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEssayer%20de%20cr%C3%A9er%20une%20liste%20pour%20chaque%20%C3%A9l%C3%A9ment%20pr%C3%A9sent%20dans%20une%20liste.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJ'ai%20d%C3%A9j%C3%A0%2C%3C%2FP%3E%3CP%3EListe%20ma%C3%AEtresse%20%3D%20%7B%22test1%22%2C%20%22test2%22%7D%26nbsp%3B%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERequis%2C%3C%2FP%3E%3CP%3EAjoutez%20la%20cha%C3%AEne%20%C2%AB%20valeur%20%C2%BB%20%C3%A0%20chaque%20%C3%A9l%C3%A9ment%20pr%C3%A9sent%20dans%20la%20MasterList%20et%20devez%20faire%20de%20chaque%20%C3%A9l%C3%A9ment%20une%20liste%20individuelle.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Evaleur%20test1%20%3D%20%7B%7D%26nbsp%3B%3B%3C%2FP%3E%3CP%3Evaleur%20test2%20%3D%20%7B%7D%26nbsp%3B%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMerci%2C%20Alex.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-464319%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3EIng%C3%A9nierie%20Qualit%C3%A9%20et%20Proc%C3%A9d%C3%A9s%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eles%20fen%C3%AAtres%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-465322%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Cr%C3%A9er%20une%20liste%20pour%20chaque%20%C3%A9l%C3%A9ment%20pr%C3%A9sent%20dans%20une%20liste.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-465322%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJuste%20un%20petit%20point%26nbsp%3B%3A%20en%20utilisant%3CCODE%20class%3D%22%20language-jsl%22%3E%20Eval(%20Parse(%20Eval%20Insert(%20...%20)%20)%20)%3C%2FCODE%3E%20peut%20%C3%AAtre%20quelque%20peu%20fastidieux%20et%20lent%20(m%C3%AAme%20si%20le%20ralentissement%20n'est%20apparent%20qu'avec%20un%20grand%20nombre%20d'appels).Vous%20pouvez%20l'%C3%A9viter%20en%20acc%C3%A9dant%20directement%20%C3%A0%20l'espace%20de%20noms%20%22ici%22%2C%20comme%20suit%26nbsp%3B%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0A%0AMasterList%20%3D%20%7B%22test1%22%2C%20%22test2%22%7D%3B%0A%0Ahere%20%3D%20Namespace(%20%22here%22%20)%3B%0A%2F%2F%20many%20variables%20containing%20lists%0AFor%20Each(%20%7Bitem%7D%2C%20Masterlist%2C%20here%5Bitem%20%7C%7C%20%22value%22%5D%20%3D%20%7B%7D%20)%3B%0AShow(%20test1value%2C%20test2value%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-465070%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Cr%C3%A9er%20une%20liste%20pour%20chaque%20%C3%A9l%C3%A9ment%20pr%C3%A9sent%20dans%20une%20liste.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-465070%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EApproche%20l%C3%A9g%C3%A8rement%20diff%C3%A9rente%20utilisant%20un%20tableau%20associatif%26nbsp%3B%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0A%0AMasterList%20%3D%20%7B%22test1%22%2C%20%22test2%22%7D%3B%0A%0A%2F%2F%20associative%20array%20containing%20lists%0AMaster_AA%20%3D%20Associative%20Array()%3B%0Afor%20(i%20%3D%201%2C%20i%20%26lt%3B%3D%20nitems(masterlist)%2C%20i%2B%2B%2C%0A%20one_key%20%3D%20masterlist%5Bi%5D%3B%0A%20master_aa%5Bone_key%5D%20%3D%20%7B%7D%3B%0A)%3B%0A%0A%2F%2F%20Load%20the%20lists%20with%20some%20data%0Ainsertinto(master_aa%5B%22test1%22%5D%2C%20%7B1%2C%202%2C%203%7D)%3B%0Ainsertinto(master_aa%5B%22test2%22%5D%2C%20%7B4%2C%205%2C%206%7D)%3B%0A%0Aprint(master_aa)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ESortir%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%5B%22test1%22%20%3D%26gt%3B%20%7B1%2C%202%2C%203%7D%2C%20%22test2%22%20%3D%26gt%3B%20%7B4%2C%205%2C%206%7D%5D%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-464651%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Cr%C3%A9er%20une%20liste%20pour%20chaque%20%C3%A9l%C3%A9ment%20pr%C3%A9sent%20dans%20une%20liste.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-464651%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EMerci%20Georg%20et%20Mark%20!!%3C%2FP%3E%3CP%3ELes%20deux%20solutions%20ont%20fait%20l'affaire%20!!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-464625%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Cr%C3%A9er%20une%20liste%20pour%20chaque%20%C3%A9l%C3%A9ment%20pr%C3%A9sent%20dans%20une%20liste.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-464625%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EExcellente%20id%C3%A9e%20de%20Mark.%3C%2FP%3E%0A%3CP%3ECela%20peut%20ressembler%20%C3%A0%20ceci%20dans%20votre%20cas.%20Vous%20pouvez%20g%C3%A9rer%20efficacement%20de%20nombreuses%20listes%20dans%20un%20tableau%20associatif.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0A%0AMasterList%20%3D%20%7B%22test1%22%2C%20%22test2%22%7D%3B%0A%0A%2F%2F%20many%20variables%20containing%20lists%0AFor%20Each(%20%7Bitem%7D%2C%20Masterlist%2C%20Eval(%20Parse(%20Eval%20Insert(%20%22%5Eitem%5Evalue%3D%20%7B%7D%3B%22%20)%20)%20)%20)%3B%0AShow(%20test1value%2C%20test2value%20)%3B%0A%0A%2F%2F%20associative%20array%20containing%20lists%0AMaster_AA%20%3D%20Associative%20Array()%3B%0AFor%20Each(%20%7Bitem%2C%20index%7D%2C%20Masterlist%2C%20Master_AA%5BMasterlist%5Bindex%5D%20%7C%7C%20%22value%22%5D%20%3D%20%7B%7D%20)%3B%3CBR%20%2F%3EMaster_AA%5B%22test1value%22%5D%20%3D%20%7B1%2C%202%2C%203%7D%3B%0AFor%20Each(%20%7Bkey%7D%2C%20Master_AA%2C%20Show(%20key%2C%20Master_AA%5Bkey%5D%20)%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-464384%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Cr%C3%A9er%20une%20liste%20pour%20chaque%20%C3%A9l%C3%A9ment%20pr%C3%A9sent%20dans%20une%20liste.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-464384%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EVous%20voudrez%20peut-%C3%AAtre%20utiliser%3CA%20href%3D%22https%3A%2F%2Fwww.jmp.com%2Fsupport%2Fhelp%2Fen%2F16.2%2F%23page%2Fjmp%2Fassociative-arrays.shtml%23%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%20Tableaux%20associatifs%3C%2FA%3E%20au%20lieu%20de%20listes.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-464362%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Cr%C3%A9er%20une%20liste%20pour%20chaque%20%C3%A9l%C3%A9ment%20pr%C3%A9sent%20dans%20une%20liste.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-464362%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ECela%20aide%20probablement%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0A%0AMasterList%20%3D%20%7B%22test1%22%2C%20%22test2%22%7D%3B%0A%0AFor%20Each(%20%7Bitem%7D%2C%20Masterlist%2C%20Eval(%20Parse(%20Eval%20Insert(%20%22%5Eitem%5Evalue%3D%20%7B%7D%3B%22%20)%20)%20)%20)%3B%0AShow(%20test1value%2C%20test2value%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
AlexR846
Level III

Create a list for each elements present in a list.

Dear All,

 

Trying to create a list for each items present in a list.

 

Already have,

MasterList = {"test1", "test2"};

 

Required,

Append the string "value" to each items present in the MasterList and have to make each item as an individual list.

 

test1value = {};

test2value = {};

 

Thanks, Alex.

1 ACCEPTED SOLUTION

Accepted Solutions
Georg
Level VII

Re: Create a list for each elements present in a list.

Great Idea of Mark. 

This may look as follows in your case. You can effectively manage many lists in an Associative Array.

 

Names Default To Here( 1 );

MasterList = {"test1", "test2"};

// many variables containing lists
For Each( {item}, Masterlist, Eval( Parse( Eval Insert( "^item^value= {};" ) ) ) );
Show( test1value, test2value );

// associative array containing lists
Master_AA = Associative Array();
For Each( {item, index}, Masterlist, Master_AA[Masterlist[index] || "value"] = {} );
Master_AA["test1value"] = {1, 2, 3}; For Each( {key}, Master_AA, Show( key, Master_AA[key] ) );
Georg

View solution in original post

6 REPLIES 6
Georg
Level VII

Re: Create a list for each elements present in a list.

Probably this helps

Names Default To Here( 1 );

MasterList = {"test1", "test2"};

For Each( {item}, Masterlist, Eval( Parse( Eval Insert( "^item^value= {};" ) ) ) );
Show( test1value, test2value );
Georg

Re: Create a list for each elements present in a list.

You might want to use Associative Arrays instead of Lists.

Georg
Level VII

Re: Create a list for each elements present in a list.

Great Idea of Mark. 

This may look as follows in your case. You can effectively manage many lists in an Associative Array.

 

Names Default To Here( 1 );

MasterList = {"test1", "test2"};

// many variables containing lists
For Each( {item}, Masterlist, Eval( Parse( Eval Insert( "^item^value= {};" ) ) ) );
Show( test1value, test2value );

// associative array containing lists
Master_AA = Associative Array();
For Each( {item, index}, Masterlist, Master_AA[Masterlist[index] || "value"] = {} );
Master_AA["test1value"] = {1, 2, 3}; For Each( {key}, Master_AA, Show( key, Master_AA[key] ) );
Georg
AlexR846
Level III

Re: Create a list for each elements present in a list.

Thank you Georg, & Mark !!

Both solutions did the job !!

pmroz
Super User

Re: Create a list for each elements present in a list.

Slightly different approach using an associative array:

Names Default To Here( 1 );

MasterList = {"test1", "test2"};

// associative array containing lists
Master_AA = Associative Array();
for (i = 1, i <= nitems(masterlist), i++,
	one_key = masterlist[i];
	master_aa[one_key] = {};
);

// Load the lists with some data
insertinto(master_aa["test1"], {1, 2, 3});
insertinto(master_aa["test2"], {4, 5, 6});

print(master_aa);

Output:

["test1" => {1, 2, 3}, "test2" => {4, 5, 6}]
ErraticAttack
Level VI

Re: Create a list for each elements present in a list.

Just a quick point -- using Eval( Parse( Eval Insert( ... ) ) ) can be somewhat cumbersome and slow (although the slowdown is only apparent with a great many calls).  You can avoid it by accessing the "here" namespace directly, as follows:

 

Names Default To Here( 1 );

MasterList = {"test1", "test2"};

here = Namespace( "here" );
// many variables containing lists
For Each( {item}, Masterlist, here[item || "value"] = {} );
Show( test1value, test2value );
Jordan

Recommended Articles