How to use Select for a specific nested list level
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I would like to parse every sublist of a nested list and select only those elements that have a certain length, i.e., smaller than 10 elements while maintaining the list structure. Is there any quick trick that makes it work ?
Matrix =
O1,2,22,24,28,14,D1,
O1,1,21,23,27,13,D1,
O1,2,22,24,28,27,13,D1,
O1,2,22,24,28,14,13,D1,
O1,2,22,24,23,27,13,D1,
O1,2,22,21,23,27,13,D1,
O1,2,1,21,23,27,13,D1,
O1,1,21,23,27,28,14,D1,
O1,1,21,23,27,13,14,D1,
O1,1,21,23,24,28,14,D1,
O1,1,21,22,24,28,14,D1,
O1,1,2,22,24,28,14,D1,
O1,2,22,24,28,27,13,14,D1,
O1,2,22,24,23,27,28,14,D1,
O1,1,2,22,21,23,25,9,10,26,24,28,18,17,27,13,14,D1,
O1,1,2,22,21,23,25,9,10,26,24,28,16,15,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,20,19,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,18,PoP2,17,27,13,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,18,17,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,16,15,27,13,14,D1,
O1,1,2,22,21,23,5,PoP1,6,24,28,18,PoP2,17,27,13,14,D1,
O1,2,1,21,22,24,26,12,11,25,23,27,17,PoP2,18,28,14,13,D1,
O1,2,1,21,22,24,26,10,9,25,23,27,17,PoP2,18,28,14,13,D1,
O1,2,1,21,22,24,26,8,7,25,23,27,17,PoP2,18,28,14,13,D1,
O1,1,2,22,21,23,25,11,12,26,24,28,18,PoP2,17,27,13,14,D1,
O1,1,2,22,21,23,25,9,10,26,24,28,18,PoP2,17,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,18,PoP2,17,27,13,14,D1
the result needs to be :
O1,2,22,24,28,14,D1,
O1,1,21,23,27,13,D1,
O1,2,22,24,28,27,13,D1,
O1,2,22,24,28,14,13,D1,
O1,2,22,24,23,27,13,D1,
O1,2,22,21,23,27,13,D1,
O1,2,1,21,23,27,13,D1,
O1,1,21,23,27,28,14,D1,
O1,1,21,23,27,13,14,D1,
O1,1,21,23,24,28,14,D1,
O1,1,21,22,24,28,14,D1,
O1,1,2,22,24,28,14,D1,
O1,2,22,24,28,27,13,14,D1,
O1,2,22,24,23,27,28,14,D1
Appreciated any help,
list-manipulation filtering
add a comment |Â
up vote
4
down vote
favorite
I would like to parse every sublist of a nested list and select only those elements that have a certain length, i.e., smaller than 10 elements while maintaining the list structure. Is there any quick trick that makes it work ?
Matrix =
O1,2,22,24,28,14,D1,
O1,1,21,23,27,13,D1,
O1,2,22,24,28,27,13,D1,
O1,2,22,24,28,14,13,D1,
O1,2,22,24,23,27,13,D1,
O1,2,22,21,23,27,13,D1,
O1,2,1,21,23,27,13,D1,
O1,1,21,23,27,28,14,D1,
O1,1,21,23,27,13,14,D1,
O1,1,21,23,24,28,14,D1,
O1,1,21,22,24,28,14,D1,
O1,1,2,22,24,28,14,D1,
O1,2,22,24,28,27,13,14,D1,
O1,2,22,24,23,27,28,14,D1,
O1,1,2,22,21,23,25,9,10,26,24,28,18,17,27,13,14,D1,
O1,1,2,22,21,23,25,9,10,26,24,28,16,15,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,20,19,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,18,PoP2,17,27,13,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,18,17,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,16,15,27,13,14,D1,
O1,1,2,22,21,23,5,PoP1,6,24,28,18,PoP2,17,27,13,14,D1,
O1,2,1,21,22,24,26,12,11,25,23,27,17,PoP2,18,28,14,13,D1,
O1,2,1,21,22,24,26,10,9,25,23,27,17,PoP2,18,28,14,13,D1,
O1,2,1,21,22,24,26,8,7,25,23,27,17,PoP2,18,28,14,13,D1,
O1,1,2,22,21,23,25,11,12,26,24,28,18,PoP2,17,27,13,14,D1,
O1,1,2,22,21,23,25,9,10,26,24,28,18,PoP2,17,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,18,PoP2,17,27,13,14,D1
the result needs to be :
O1,2,22,24,28,14,D1,
O1,1,21,23,27,13,D1,
O1,2,22,24,28,27,13,D1,
O1,2,22,24,28,14,13,D1,
O1,2,22,24,23,27,13,D1,
O1,2,22,21,23,27,13,D1,
O1,2,1,21,23,27,13,D1,
O1,1,21,23,27,28,14,D1,
O1,1,21,23,27,13,14,D1,
O1,1,21,23,24,28,14,D1,
O1,1,21,22,24,28,14,D1,
O1,1,2,22,24,28,14,D1,
O1,2,22,24,28,27,13,14,D1,
O1,2,22,24,23,27,28,14,D1
Appreciated any help,
list-manipulation filtering
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I would like to parse every sublist of a nested list and select only those elements that have a certain length, i.e., smaller than 10 elements while maintaining the list structure. Is there any quick trick that makes it work ?
Matrix =
O1,2,22,24,28,14,D1,
O1,1,21,23,27,13,D1,
O1,2,22,24,28,27,13,D1,
O1,2,22,24,28,14,13,D1,
O1,2,22,24,23,27,13,D1,
O1,2,22,21,23,27,13,D1,
O1,2,1,21,23,27,13,D1,
O1,1,21,23,27,28,14,D1,
O1,1,21,23,27,13,14,D1,
O1,1,21,23,24,28,14,D1,
O1,1,21,22,24,28,14,D1,
O1,1,2,22,24,28,14,D1,
O1,2,22,24,28,27,13,14,D1,
O1,2,22,24,23,27,28,14,D1,
O1,1,2,22,21,23,25,9,10,26,24,28,18,17,27,13,14,D1,
O1,1,2,22,21,23,25,9,10,26,24,28,16,15,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,20,19,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,18,PoP2,17,27,13,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,18,17,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,16,15,27,13,14,D1,
O1,1,2,22,21,23,5,PoP1,6,24,28,18,PoP2,17,27,13,14,D1,
O1,2,1,21,22,24,26,12,11,25,23,27,17,PoP2,18,28,14,13,D1,
O1,2,1,21,22,24,26,10,9,25,23,27,17,PoP2,18,28,14,13,D1,
O1,2,1,21,22,24,26,8,7,25,23,27,17,PoP2,18,28,14,13,D1,
O1,1,2,22,21,23,25,11,12,26,24,28,18,PoP2,17,27,13,14,D1,
O1,1,2,22,21,23,25,9,10,26,24,28,18,PoP2,17,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,18,PoP2,17,27,13,14,D1
the result needs to be :
O1,2,22,24,28,14,D1,
O1,1,21,23,27,13,D1,
O1,2,22,24,28,27,13,D1,
O1,2,22,24,28,14,13,D1,
O1,2,22,24,23,27,13,D1,
O1,2,22,21,23,27,13,D1,
O1,2,1,21,23,27,13,D1,
O1,1,21,23,27,28,14,D1,
O1,1,21,23,27,13,14,D1,
O1,1,21,23,24,28,14,D1,
O1,1,21,22,24,28,14,D1,
O1,1,2,22,24,28,14,D1,
O1,2,22,24,28,27,13,14,D1,
O1,2,22,24,23,27,28,14,D1
Appreciated any help,
list-manipulation filtering
I would like to parse every sublist of a nested list and select only those elements that have a certain length, i.e., smaller than 10 elements while maintaining the list structure. Is there any quick trick that makes it work ?
Matrix =
O1,2,22,24,28,14,D1,
O1,1,21,23,27,13,D1,
O1,2,22,24,28,27,13,D1,
O1,2,22,24,28,14,13,D1,
O1,2,22,24,23,27,13,D1,
O1,2,22,21,23,27,13,D1,
O1,2,1,21,23,27,13,D1,
O1,1,21,23,27,28,14,D1,
O1,1,21,23,27,13,14,D1,
O1,1,21,23,24,28,14,D1,
O1,1,21,22,24,28,14,D1,
O1,1,2,22,24,28,14,D1,
O1,2,22,24,28,27,13,14,D1,
O1,2,22,24,23,27,28,14,D1,
O1,1,2,22,21,23,25,9,10,26,24,28,18,17,27,13,14,D1,
O1,1,2,22,21,23,25,9,10,26,24,28,16,15,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,20,19,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,18,PoP2,17,27,13,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,18,17,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,16,15,27,13,14,D1,
O1,1,2,22,21,23,5,PoP1,6,24,28,18,PoP2,17,27,13,14,D1,
O1,2,1,21,22,24,26,12,11,25,23,27,17,PoP2,18,28,14,13,D1,
O1,2,1,21,22,24,26,10,9,25,23,27,17,PoP2,18,28,14,13,D1,
O1,2,1,21,22,24,26,8,7,25,23,27,17,PoP2,18,28,14,13,D1,
O1,1,2,22,21,23,25,11,12,26,24,28,18,PoP2,17,27,13,14,D1,
O1,1,2,22,21,23,25,9,10,26,24,28,18,PoP2,17,27,13,14,D1,
O1,1,2,22,21,23,25,7,8,26,24,28,18,PoP2,17,27,13,14,D1
the result needs to be :
O1,2,22,24,28,14,D1,
O1,1,21,23,27,13,D1,
O1,2,22,24,28,27,13,D1,
O1,2,22,24,28,14,13,D1,
O1,2,22,24,23,27,13,D1,
O1,2,22,21,23,27,13,D1,
O1,2,1,21,23,27,13,D1,
O1,1,21,23,27,28,14,D1,
O1,1,21,23,27,13,14,D1,
O1,1,21,23,24,28,14,D1,
O1,1,21,22,24,28,14,D1,
O1,1,2,22,24,28,14,D1,
O1,2,22,24,28,27,13,14,D1,
O1,2,22,24,23,27,28,14,D1
Appreciated any help,
list-manipulation filtering
list-manipulation filtering
edited 38 mins ago
Carl Woll
63.6k282165
63.6k282165
asked 1 hour ago
Besi
453
453
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
Map[Select[Length[#] < 10 &], Matrix, 2]
add a comment |Â
up vote
2
down vote
I would again use DeleteCases
just like in my answer to your last question Filtering nested lists while maintaining the list level:
DeleteCases[Matrix, s_List?(Length[#]>=10&), -2]
O1, 2, 22, 24, 28, 14, D1, O1, 1, 21, 23, 27, 13, D1, O1, 2, 22, 24,
28, 27, 13, D1, O1, 2, 22, 24, 28, 14, 13, D1, O1, 2, 22, 24, 23, 27,
13, D1, O1, 2, 22, 21, 23, 27, 13, D1, O1, 2, 1, 21, 23, 27, 13,
D1, O1, 1, 21, 23, 27, 28, 14, D1, O1, 1, 21, 23, 27, 13, 14,
D1, O1, 1, 21, 23, 24, 28, 14, D1, O1, 1, 21, 22, 24, 28, 14,
D1, O1, 1, 2, 22, 24, 28, 14, D1, O1, 2, 22, 24, 28, 27, 13, 14,
D1, O1, 2, 22, 24, 23, 27, 28, 14, D1
Not sure why, but applying this does not work correctly. Whereas, the answer given by Mr. Schumacher works. Thanks anyway.
â Besi
22 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Map[Select[Length[#] < 10 &], Matrix, 2]
add a comment |Â
up vote
4
down vote
accepted
Map[Select[Length[#] < 10 &], Matrix, 2]
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Map[Select[Length[#] < 10 &], Matrix, 2]
Map[Select[Length[#] < 10 &], Matrix, 2]
answered 1 hour ago
Henrik Schumacher
43.3k263129
43.3k263129
add a comment |Â
add a comment |Â
up vote
2
down vote
I would again use DeleteCases
just like in my answer to your last question Filtering nested lists while maintaining the list level:
DeleteCases[Matrix, s_List?(Length[#]>=10&), -2]
O1, 2, 22, 24, 28, 14, D1, O1, 1, 21, 23, 27, 13, D1, O1, 2, 22, 24,
28, 27, 13, D1, O1, 2, 22, 24, 28, 14, 13, D1, O1, 2, 22, 24, 23, 27,
13, D1, O1, 2, 22, 21, 23, 27, 13, D1, O1, 2, 1, 21, 23, 27, 13,
D1, O1, 1, 21, 23, 27, 28, 14, D1, O1, 1, 21, 23, 27, 13, 14,
D1, O1, 1, 21, 23, 24, 28, 14, D1, O1, 1, 21, 22, 24, 28, 14,
D1, O1, 1, 2, 22, 24, 28, 14, D1, O1, 2, 22, 24, 28, 27, 13, 14,
D1, O1, 2, 22, 24, 23, 27, 28, 14, D1
Not sure why, but applying this does not work correctly. Whereas, the answer given by Mr. Schumacher works. Thanks anyway.
â Besi
22 mins ago
add a comment |Â
up vote
2
down vote
I would again use DeleteCases
just like in my answer to your last question Filtering nested lists while maintaining the list level:
DeleteCases[Matrix, s_List?(Length[#]>=10&), -2]
O1, 2, 22, 24, 28, 14, D1, O1, 1, 21, 23, 27, 13, D1, O1, 2, 22, 24,
28, 27, 13, D1, O1, 2, 22, 24, 28, 14, 13, D1, O1, 2, 22, 24, 23, 27,
13, D1, O1, 2, 22, 21, 23, 27, 13, D1, O1, 2, 1, 21, 23, 27, 13,
D1, O1, 1, 21, 23, 27, 28, 14, D1, O1, 1, 21, 23, 27, 13, 14,
D1, O1, 1, 21, 23, 24, 28, 14, D1, O1, 1, 21, 22, 24, 28, 14,
D1, O1, 1, 2, 22, 24, 28, 14, D1, O1, 2, 22, 24, 28, 27, 13, 14,
D1, O1, 2, 22, 24, 23, 27, 28, 14, D1
Not sure why, but applying this does not work correctly. Whereas, the answer given by Mr. Schumacher works. Thanks anyway.
â Besi
22 mins ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
I would again use DeleteCases
just like in my answer to your last question Filtering nested lists while maintaining the list level:
DeleteCases[Matrix, s_List?(Length[#]>=10&), -2]
O1, 2, 22, 24, 28, 14, D1, O1, 1, 21, 23, 27, 13, D1, O1, 2, 22, 24,
28, 27, 13, D1, O1, 2, 22, 24, 28, 14, 13, D1, O1, 2, 22, 24, 23, 27,
13, D1, O1, 2, 22, 21, 23, 27, 13, D1, O1, 2, 1, 21, 23, 27, 13,
D1, O1, 1, 21, 23, 27, 28, 14, D1, O1, 1, 21, 23, 27, 13, 14,
D1, O1, 1, 21, 23, 24, 28, 14, D1, O1, 1, 21, 22, 24, 28, 14,
D1, O1, 1, 2, 22, 24, 28, 14, D1, O1, 2, 22, 24, 28, 27, 13, 14,
D1, O1, 2, 22, 24, 23, 27, 28, 14, D1
I would again use DeleteCases
just like in my answer to your last question Filtering nested lists while maintaining the list level:
DeleteCases[Matrix, s_List?(Length[#]>=10&), -2]
O1, 2, 22, 24, 28, 14, D1, O1, 1, 21, 23, 27, 13, D1, O1, 2, 22, 24,
28, 27, 13, D1, O1, 2, 22, 24, 28, 14, 13, D1, O1, 2, 22, 24, 23, 27,
13, D1, O1, 2, 22, 21, 23, 27, 13, D1, O1, 2, 1, 21, 23, 27, 13,
D1, O1, 1, 21, 23, 27, 28, 14, D1, O1, 1, 21, 23, 27, 13, 14,
D1, O1, 1, 21, 23, 24, 28, 14, D1, O1, 1, 21, 22, 24, 28, 14,
D1, O1, 1, 2, 22, 24, 28, 14, D1, O1, 2, 22, 24, 28, 27, 13, 14,
D1, O1, 2, 22, 24, 23, 27, 28, 14, D1
answered 40 mins ago
Carl Woll
63.6k282165
63.6k282165
Not sure why, but applying this does not work correctly. Whereas, the answer given by Mr. Schumacher works. Thanks anyway.
â Besi
22 mins ago
add a comment |Â
Not sure why, but applying this does not work correctly. Whereas, the answer given by Mr. Schumacher works. Thanks anyway.
â Besi
22 mins ago
Not sure why, but applying this does not work correctly. Whereas, the answer given by Mr. Schumacher works. Thanks anyway.
â Besi
22 mins ago
Not sure why, but applying this does not work correctly. Whereas, the answer given by Mr. Schumacher works. Thanks anyway.
â Besi
22 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f185091%2fhow-to-use-select-for-a-specific-nested-list-level%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password