Message Boards Message Boards

0
|
2322 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:

Is AppendTo a good approach to making a list of lists?

Posted 11 years ago
I have lists such as
{{1, 1}, {8, 2}, {7, 4}, {1, 1}}
then
{{8, 2}, {15, 5}, {7, 4}, {8, 2}}
then
{{18, 4}, {15, 5}, {8, 2}, {18, 4}}
I want to create  
{{{1, 1}, {8, 2}, {7, 4}, {1, 1}} , {{8, 2}, {15, 5}, {7, 4}, {8, 2}} , {{18, 4}, {15, 5}, {8, 2}, {18, 4}}}
I have tried AppendTo first list , second list, then AppendTo result to third list, but get
{{1, 1}, {8, 2}, {7, 4}, {1, 1}, {{8, 2}, {15, 5}, {7, 4}, {8, 2}}, {{18, 4}, {15, 5}, {8, 2}, {18, 4}}}
which is the wrong nesting. Any ideas?
Posted 11 years ago
You can just nest them in the top list:
In[1]:= lst1 = {{1, 1}, {8, 2}, {7, 4}, {1, 1}};
lst2 = {{8, 2}, {15, 5}, {7, 4}, {8, 2}};
lst3 = {{18, 4}, {15, 5}, {8, 2}, {18, 4}};
{lst1, lst2, lst3}

Out[4]= {{{1, 1}, {8, 2}, {7, 4}, {1, 1}}, {{8, 2}, {15, 5}, {7,
   4}, {8, 2}}, {{18, 4}, {15, 5}, {8, 2}, {18, 4}}}

Best,

David
POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract