If I have a list that contains 16 sublist (enclosed in 2 curly

  • Thread starter Thread starter Sarah rob
  • Start date Start date
  • Tags Tags
    List
AI Thread Summary
The discussion revolves around creating two new lists from a given list L1 that contains 16 sublists. The user seeks to extract specific sublists into two separate lists based on their indices. There is a focus on using the Mod function for this extraction, but clarity is needed regarding the structure of L1 and the definition of sublists. Participants suggest that understanding the exact contents of L1 is crucial for constructing the desired lists accurately. Ultimately, the conversation emphasizes the importance of precise indexing and the use of the Part operator to achieve the intended outcome.
Sarah rob
Messages
16
Reaction score
0
If I have a list that contains 16 sublist (enclosed in 2 curly bracets),
L1 = {{{1, 1}, {1, 5}, {1, 8}}, {{2, 6}, {1, 10}, {0, 12}},
{{3, 2}, {1, 4}, {0, 15}}, {{1, 8}, {1, 14}, {2, 17}},
{{1, 2}, {2, 8}, {3, 12}}, {{2, 6}, {2, 11}, {2, 18}},
{{3, 6}, {1, 9}, {2,17}}, {{1, 8}, {3, 18}, {2, 19}} ... ...};

could I create a list from L1 that is made up of sublist 1, 2, 3, 4, 9, 10, 11,
12 and another that is made up of sublist 5, 6, 7, 8, 13, 14, 15, 16

I have had the idea of using Mod but don' t quite know how to
constuct it:

sub = 0;
sub++;
If[Mod[sub, 8, 1] < 4, Map[something?, L1], Map[something?,L1]]
 
Physics news on Phys.org


With the nested {} in your L1 it seems that you have a 3 dimensional "matrix." Is that what you really have? Or do you have some extra {} that are not really in your data?

If all those {} are actually present then is sublist 1 = {1, 1} or is it {{1, 1}, {1, 5}, {1, 8}}?

Perhaps showing what L2 and L3 should have as values given your L1 would be the most precise way of describing what you need.

If you can answer those questions then it will be possible to show you ways to do what you want.
 


The Part operator [[]] can take a list as an argument. E.g.

L1[[{1, 2, 3, 4, 9, 10, 11, 12}]]
 


Sorry, didn't make it very clear

sublist 1 = {{1, 1}, {1, 5}, {1, 8}}
sublist 2 = {{2, 6}, {1, 10}, {0, 12}} ...

so I want a new list that will be {sublist 1,sublist 2,sublist 3,sublist 4,sublist 9,sublist 10, sublist 11,sublist 12}
And another {sublist 5,sublist 6,sublist 7,sublist 8,sublist 13,sublist 14, sublist 15,sublist 16}
 


As long as Length[L1] is a multiple of 8

In[1]:=L1={{{1,1},{1,5},{1,8}},{{2,6},{1,10},{0,12}},{{3,2},{1,4},{0,15}},{{1,8},{1,14},{2,17}},
{{1,2},{2,8},{3,12}},{{2,6},{2,11},{2,18}},{{3,6},{1,9},{2,17}},{{1,8},{3,18},{2,19}}};

In[2]:=L2=L1[[Flatten[Table[8j+i,{j,0,(Length[L1]-8)/8},{i,1,4}]]]]

In[3]:=L3=L1[[Flatten[Table[8j+i+4,{j,0,(Length[L1]-8)/8},{i,1,4}]]]]
 

Similar threads

Replies
22
Views
3K
Replies
2
Views
2K
Replies
1
Views
2K
Replies
7
Views
3K
Replies
7
Views
4K
Replies
2
Views
2K
Replies
1
Views
989
Back
Top