- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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] ) );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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 );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Create a list for each elements present in a list.
You might want to use Associative Arrays instead of Lists.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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] ) );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Create a list for each elements present in a list.
Thank you Georg, & Mark !!
Both solutions did the job !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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}]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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 );