Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.6K Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:

[?] Select several elements from a list?

Hi,

How do I get List1 and List2 from the main List:

List = {{a1, a2, a3, a4, a5, a6, a7, a8}, {b1, b2, b3, b4, b5, b6, b7,
         b8}, {c1, c2, c3, c4, c5, c6, c7, c8}};

    List1 = {a1, a2, a3, b1, b2, b3, c1, c2, c3}

    List2 = {a6, a7, a8, b6, b7, b8, c6, c7, c8}

Thank you so much.

POSTED BY: M.A. Ghorbani
2 Replies
Posted 6 years ago

You could use Part together with Span

In[1]:= list = {{a1, a2, a3, a4, a5, a6, a7, a8}, {b1, b2, b3, b4, b5,
     b6, b7, b8}, {c1, c2, c3, c4, c5, c6, c7, c8}};

In[2]:= list1 = list[[All, 1 ;; 3]] // Flatten
Out[2]= {a1, a2, a3, b1, b2, b3, c1, c2, c3}

In[3]:= list2 = list[[All, 6 ;; 8]] // Flatten
Out[3]= {a6, a7, a8, b6, b7, b8, c6, c7, c8}
POSTED BY: Hans Milton

Thank so much, Hans.

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