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

  • Thread starter Sarah rob
  • Start date
  • Tags
    List
In summary, there are two possible lists that can be created from L1, one containing sublist 1, 2, 3, 4, 9, 10, 11, 12 and the other containing sublist 5, 6, 7, 8, 13, 14, 15, 16. This can be achieved by using the Part operator to select the appropriate sublists from L1, taking into account the length of the list.
  • #1
Sarah rob
16
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
  • #2


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.
 
  • #3


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

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


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}
 
  • #5


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}]]]]
 

1. What is a sublist?

A sublist is a smaller list that is contained within a larger list. It is enclosed in curly brackets and is used to categorize or organize items within the larger list.

2. How many sublists can be contained within a list?

There is no limit to the number of sublists that can be contained within a list. However, it is important to keep the list organized and manageable for readability and ease of use.

3. Can sublists be nested within each other?

Yes, sublists can be nested within each other. This means that a sublist can contain another sublist, creating a hierarchy of lists within the original list.

4. What is the purpose of using sublists?

Sublists are used to categorize and organize items within a larger list. This can make the list easier to read and understand, as well as provide a structure for grouping related items together.

5. How do I access items within a sublist?

To access items within a sublist, you can use the index of the sublist within the larger list. For example, if the sublist is the third item in the larger list, you can use the index [2] to access the items within that sublist.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
352
  • MATLAB, Maple, Mathematica, LaTeX
Replies
22
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Nuclear Engineering
Replies
7
Views
2K
  • Nuclear Engineering
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • General Math
Replies
24
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
Back
Top