How to use Select for a specific nested list level

The name of the pictureThe name of the pictureThe name of the pictureClash 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,










share|improve this question



























    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,










    share|improve this question

























      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,










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 38 mins ago









      Carl Woll

      63.6k282165




      63.6k282165










      asked 1 hour ago









      Besi

      453




      453




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          Map[Select[Length[#] < 10 &], Matrix, 2]





          share|improve this answer



























            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







            share|improve this answer




















            • Not sure why, but applying this does not work correctly. Whereas, the answer given by Mr. Schumacher works. Thanks anyway.
              – Besi
              22 mins ago











            Your Answer





            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "387"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            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






























            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]





            share|improve this answer
























              up vote
              4
              down vote



              accepted










              Map[Select[Length[#] < 10 &], Matrix, 2]





              share|improve this answer






















                up vote
                4
                down vote



                accepted







                up vote
                4
                down vote



                accepted






                Map[Select[Length[#] < 10 &], Matrix, 2]





                share|improve this answer












                Map[Select[Length[#] < 10 &], Matrix, 2]






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 1 hour ago









                Henrik Schumacher

                43.3k263129




                43.3k263129




















                    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







                    share|improve this answer




















                    • Not sure why, but applying this does not work correctly. Whereas, the answer given by Mr. Schumacher works. Thanks anyway.
                      – Besi
                      22 mins ago















                    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







                    share|improve this answer




















                    • Not sure why, but applying this does not work correctly. Whereas, the answer given by Mr. Schumacher works. Thanks anyway.
                      – Besi
                      22 mins ago













                    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







                    share|improve this answer












                    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








                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    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

















                    • 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


















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    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













































































                    Comments

                    Popular posts from this blog

                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

                    Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                    Confectionery