List of lists of lists how to make a map recursively

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite












 list = ab, ad, be, br, pb, cd, cr, ce, fo, gf, gh, gv, gg, ne, ks, kd, kl, sa, sx, sr, sdr, svd, ssfrt, styi, sfc, sfb, smaa, ja, aw


I would like to produce all this outputs with a Fold or Nest or so but it's over my level ...



tdl1 = Table[
If[ListQ[list[[i]]], i, Length[list[[i]]], list[[i]]],
i, Length[list]
]



ab, ad, 3, 4, aw




tdl2 = Table[
If[ListQ[list[[3, i]]], i, Length[list[[3, i]]], list[[3, i]]],
i, tdl1[[3, 2]]
]



be, br, pb, 4, 8




tdl3 = Table[
If[ListQ[list[[3, 4, i]]], i, Length[list[[3, 4, i]]], list[[3, 4, i]]],
i, tdl2[[4, 2]]
]



cd, cr, ce, 4, 1, 5, 4, ne, 7, 3, 8, 4




tdl4 = Table[
If[ListQ[list[[3, 4, 4, i]]], i, Length[list[[3, 4, 4, i]]], list[[3, 4, 4, i]]],
i, tdl3[[4, 2]]
]



fo




tdl5 = Table[
If[ListQ[list[[3, 4, 5, i]]], i, Length[list[[3, 4, 5, i]]], list[[3, 4, 5, i]]],
i, tdl3[[5, 2]]
]



gf, gh, gv, gg




tdl6 = Table[
If[ListQ[list[[3, 4, 7, i]]], i, Length[list[[3, 4, 7, i]]], list[[3, 4, 7, i]]],
i, tdl3[[7, 2]]
]



ks, kd, kl




tdl7 = Table[
If[ListQ[list[[3, 4, 8, i]]], i, Length[list[[3, 4, 8, i]]], list[[3, 4, 8, i]]],
i, tdl3[[8, 2]]
]



sa, sx, sr, 4, 5




tdl8 = Table[
If[ListQ[list[[3, 4, 8, 4, i]]], i, Length[list[[3, 4, 8, 4, i]]], list[[3, 4, 8, 4, i]]],
i, tdl7[[4, 2]]
]



sdr, svd, 3, 2, 4, 3, ja




tdl9 = Table[
If[ListQ[list[[3, 4, 8, 4, 3, i]]], i, Length[list[[3, 4, 8, 4, 3, i]]], list[[3, 4, 8, 4, 3, i]]],
i, tdl8[[3, 2]]
]



ssfrt, styi




 tdl10 = Table[
If[ListQ[list[[3, 4, 8, 4, 4, i]]], i, Length[list[[3, 4, 8, 4, 4, i]]], list[[3, 4, 8, 4, 4, i]]],
i, tdl8[[4, 2]]
]



sfc, sfb, smaa











share|improve this question



























    up vote
    6
    down vote

    favorite












     list = ab, ad, be, br, pb, cd, cr, ce, fo, gf, gh, gv, gg, ne, ks, kd, kl, sa, sx, sr, sdr, svd, ssfrt, styi, sfc, sfb, smaa, ja, aw


    I would like to produce all this outputs with a Fold or Nest or so but it's over my level ...



    tdl1 = Table[
    If[ListQ[list[[i]]], i, Length[list[[i]]], list[[i]]],
    i, Length[list]
    ]



    ab, ad, 3, 4, aw




    tdl2 = Table[
    If[ListQ[list[[3, i]]], i, Length[list[[3, i]]], list[[3, i]]],
    i, tdl1[[3, 2]]
    ]



    be, br, pb, 4, 8




    tdl3 = Table[
    If[ListQ[list[[3, 4, i]]], i, Length[list[[3, 4, i]]], list[[3, 4, i]]],
    i, tdl2[[4, 2]]
    ]



    cd, cr, ce, 4, 1, 5, 4, ne, 7, 3, 8, 4




    tdl4 = Table[
    If[ListQ[list[[3, 4, 4, i]]], i, Length[list[[3, 4, 4, i]]], list[[3, 4, 4, i]]],
    i, tdl3[[4, 2]]
    ]



    fo




    tdl5 = Table[
    If[ListQ[list[[3, 4, 5, i]]], i, Length[list[[3, 4, 5, i]]], list[[3, 4, 5, i]]],
    i, tdl3[[5, 2]]
    ]



    gf, gh, gv, gg




    tdl6 = Table[
    If[ListQ[list[[3, 4, 7, i]]], i, Length[list[[3, 4, 7, i]]], list[[3, 4, 7, i]]],
    i, tdl3[[7, 2]]
    ]



    ks, kd, kl




    tdl7 = Table[
    If[ListQ[list[[3, 4, 8, i]]], i, Length[list[[3, 4, 8, i]]], list[[3, 4, 8, i]]],
    i, tdl3[[8, 2]]
    ]



    sa, sx, sr, 4, 5




    tdl8 = Table[
    If[ListQ[list[[3, 4, 8, 4, i]]], i, Length[list[[3, 4, 8, 4, i]]], list[[3, 4, 8, 4, i]]],
    i, tdl7[[4, 2]]
    ]



    sdr, svd, 3, 2, 4, 3, ja




    tdl9 = Table[
    If[ListQ[list[[3, 4, 8, 4, 3, i]]], i, Length[list[[3, 4, 8, 4, 3, i]]], list[[3, 4, 8, 4, 3, i]]],
    i, tdl8[[3, 2]]
    ]



    ssfrt, styi




     tdl10 = Table[
    If[ListQ[list[[3, 4, 8, 4, 4, i]]], i, Length[list[[3, 4, 8, 4, 4, i]]], list[[3, 4, 8, 4, 4, i]]],
    i, tdl8[[4, 2]]
    ]



    sfc, sfb, smaa











    share|improve this question

























      up vote
      6
      down vote

      favorite









      up vote
      6
      down vote

      favorite











       list = ab, ad, be, br, pb, cd, cr, ce, fo, gf, gh, gv, gg, ne, ks, kd, kl, sa, sx, sr, sdr, svd, ssfrt, styi, sfc, sfb, smaa, ja, aw


      I would like to produce all this outputs with a Fold or Nest or so but it's over my level ...



      tdl1 = Table[
      If[ListQ[list[[i]]], i, Length[list[[i]]], list[[i]]],
      i, Length[list]
      ]



      ab, ad, 3, 4, aw




      tdl2 = Table[
      If[ListQ[list[[3, i]]], i, Length[list[[3, i]]], list[[3, i]]],
      i, tdl1[[3, 2]]
      ]



      be, br, pb, 4, 8




      tdl3 = Table[
      If[ListQ[list[[3, 4, i]]], i, Length[list[[3, 4, i]]], list[[3, 4, i]]],
      i, tdl2[[4, 2]]
      ]



      cd, cr, ce, 4, 1, 5, 4, ne, 7, 3, 8, 4




      tdl4 = Table[
      If[ListQ[list[[3, 4, 4, i]]], i, Length[list[[3, 4, 4, i]]], list[[3, 4, 4, i]]],
      i, tdl3[[4, 2]]
      ]



      fo




      tdl5 = Table[
      If[ListQ[list[[3, 4, 5, i]]], i, Length[list[[3, 4, 5, i]]], list[[3, 4, 5, i]]],
      i, tdl3[[5, 2]]
      ]



      gf, gh, gv, gg




      tdl6 = Table[
      If[ListQ[list[[3, 4, 7, i]]], i, Length[list[[3, 4, 7, i]]], list[[3, 4, 7, i]]],
      i, tdl3[[7, 2]]
      ]



      ks, kd, kl




      tdl7 = Table[
      If[ListQ[list[[3, 4, 8, i]]], i, Length[list[[3, 4, 8, i]]], list[[3, 4, 8, i]]],
      i, tdl3[[8, 2]]
      ]



      sa, sx, sr, 4, 5




      tdl8 = Table[
      If[ListQ[list[[3, 4, 8, 4, i]]], i, Length[list[[3, 4, 8, 4, i]]], list[[3, 4, 8, 4, i]]],
      i, tdl7[[4, 2]]
      ]



      sdr, svd, 3, 2, 4, 3, ja




      tdl9 = Table[
      If[ListQ[list[[3, 4, 8, 4, 3, i]]], i, Length[list[[3, 4, 8, 4, 3, i]]], list[[3, 4, 8, 4, 3, i]]],
      i, tdl8[[3, 2]]
      ]



      ssfrt, styi




       tdl10 = Table[
      If[ListQ[list[[3, 4, 8, 4, 4, i]]], i, Length[list[[3, 4, 8, 4, 4, i]]], list[[3, 4, 8, 4, 4, i]]],
      i, tdl8[[4, 2]]
      ]



      sfc, sfb, smaa











      share|improve this question















       list = ab, ad, be, br, pb, cd, cr, ce, fo, gf, gh, gv, gg, ne, ks, kd, kl, sa, sx, sr, sdr, svd, ssfrt, styi, sfc, sfb, smaa, ja, aw


      I would like to produce all this outputs with a Fold or Nest or so but it's over my level ...



      tdl1 = Table[
      If[ListQ[list[[i]]], i, Length[list[[i]]], list[[i]]],
      i, Length[list]
      ]



      ab, ad, 3, 4, aw




      tdl2 = Table[
      If[ListQ[list[[3, i]]], i, Length[list[[3, i]]], list[[3, i]]],
      i, tdl1[[3, 2]]
      ]



      be, br, pb, 4, 8




      tdl3 = Table[
      If[ListQ[list[[3, 4, i]]], i, Length[list[[3, 4, i]]], list[[3, 4, i]]],
      i, tdl2[[4, 2]]
      ]



      cd, cr, ce, 4, 1, 5, 4, ne, 7, 3, 8, 4




      tdl4 = Table[
      If[ListQ[list[[3, 4, 4, i]]], i, Length[list[[3, 4, 4, i]]], list[[3, 4, 4, i]]],
      i, tdl3[[4, 2]]
      ]



      fo




      tdl5 = Table[
      If[ListQ[list[[3, 4, 5, i]]], i, Length[list[[3, 4, 5, i]]], list[[3, 4, 5, i]]],
      i, tdl3[[5, 2]]
      ]



      gf, gh, gv, gg




      tdl6 = Table[
      If[ListQ[list[[3, 4, 7, i]]], i, Length[list[[3, 4, 7, i]]], list[[3, 4, 7, i]]],
      i, tdl3[[7, 2]]
      ]



      ks, kd, kl




      tdl7 = Table[
      If[ListQ[list[[3, 4, 8, i]]], i, Length[list[[3, 4, 8, i]]], list[[3, 4, 8, i]]],
      i, tdl3[[8, 2]]
      ]



      sa, sx, sr, 4, 5




      tdl8 = Table[
      If[ListQ[list[[3, 4, 8, 4, i]]], i, Length[list[[3, 4, 8, 4, i]]], list[[3, 4, 8, 4, i]]],
      i, tdl7[[4, 2]]
      ]



      sdr, svd, 3, 2, 4, 3, ja




      tdl9 = Table[
      If[ListQ[list[[3, 4, 8, 4, 3, i]]], i, Length[list[[3, 4, 8, 4, 3, i]]], list[[3, 4, 8, 4, 3, i]]],
      i, tdl8[[3, 2]]
      ]



      ssfrt, styi




       tdl10 = Table[
      If[ListQ[list[[3, 4, 8, 4, 4, i]]], i, Length[list[[3, 4, 8, 4, 4, i]]], list[[3, 4, 8, 4, 4, i]]],
      i, tdl8[[4, 2]]
      ]



      sfc, sfb, smaa








      list-manipulation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago









      That Gravity Guy

      1,079512




      1,079512










      asked 3 hours ago









      Anxon Pués

      429211




      429211




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Not very pretty but shorter:



          foo // ClearAll
          foo[list_List] := Module[res
          , Sow @ MapIndexed[ If[ListQ @ #, Append[#2, Length @ #], #] &, list]
          ; foo /@ list;
          ]

          Column @ Reap[foo@list][[-1, 1]]



          ab,ad,3,4,aw
          be,br,pb,4,8
          cd,cr,ce,4,1,5,4,ne,7,3,8,4
          fo
          gf,gh,gv,gg
          ks,kd,kl
          sa,sx,sr,4,5
          sdr,svd,3,2,4,3,ja
          ssfrt,styi
          sfc,sfb,smaa



          p.s. I don't like the fact that foo needs to map list twice but otherwise the order is wrong.






          share|improve this answer




















          • It's just the kind of solution I was looking for, that makes me study deeply your foo, Thank you, Eskerrik asko
            – Anxon Pués
            2 hours ago

















          up vote
          1
          down vote













          tdl = Extract[#, Sort @ Position[#, _List], 
          Replace[#, x_List :> Flatten[Position[#, x], Length @ x], 1] &] &;

          tdl @ list // Column // TeXForm



          $beginarrayl
          textab,textad,3,4,textaw \
          textbe,textbr,textpb,4,8 \
          textcd,textcr,textce,4,1,5,4,textne,7,3,8,4 \
          textfo \
          textgf,textgh,textgv,textgg \
          textks,textkd,textkl \
          textsa,textsx,textsr,4,5 \
          textsdr,textsvd,3,2,4,3,textja \
          textssfrt,textstyi \
          textsfc,textsfb,textsmaa \
          endarray$







          share|improve this answer




















            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: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f182789%2flist-of-lists-of-lists-how-to-make-a-map-recursively%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
            3
            down vote



            accepted










            Not very pretty but shorter:



            foo // ClearAll
            foo[list_List] := Module[res
            , Sow @ MapIndexed[ If[ListQ @ #, Append[#2, Length @ #], #] &, list]
            ; foo /@ list;
            ]

            Column @ Reap[foo@list][[-1, 1]]



            ab,ad,3,4,aw
            be,br,pb,4,8
            cd,cr,ce,4,1,5,4,ne,7,3,8,4
            fo
            gf,gh,gv,gg
            ks,kd,kl
            sa,sx,sr,4,5
            sdr,svd,3,2,4,3,ja
            ssfrt,styi
            sfc,sfb,smaa



            p.s. I don't like the fact that foo needs to map list twice but otherwise the order is wrong.






            share|improve this answer




















            • It's just the kind of solution I was looking for, that makes me study deeply your foo, Thank you, Eskerrik asko
              – Anxon Pués
              2 hours ago














            up vote
            3
            down vote



            accepted










            Not very pretty but shorter:



            foo // ClearAll
            foo[list_List] := Module[res
            , Sow @ MapIndexed[ If[ListQ @ #, Append[#2, Length @ #], #] &, list]
            ; foo /@ list;
            ]

            Column @ Reap[foo@list][[-1, 1]]



            ab,ad,3,4,aw
            be,br,pb,4,8
            cd,cr,ce,4,1,5,4,ne,7,3,8,4
            fo
            gf,gh,gv,gg
            ks,kd,kl
            sa,sx,sr,4,5
            sdr,svd,3,2,4,3,ja
            ssfrt,styi
            sfc,sfb,smaa



            p.s. I don't like the fact that foo needs to map list twice but otherwise the order is wrong.






            share|improve this answer




















            • It's just the kind of solution I was looking for, that makes me study deeply your foo, Thank you, Eskerrik asko
              – Anxon Pués
              2 hours ago












            up vote
            3
            down vote



            accepted







            up vote
            3
            down vote



            accepted






            Not very pretty but shorter:



            foo // ClearAll
            foo[list_List] := Module[res
            , Sow @ MapIndexed[ If[ListQ @ #, Append[#2, Length @ #], #] &, list]
            ; foo /@ list;
            ]

            Column @ Reap[foo@list][[-1, 1]]



            ab,ad,3,4,aw
            be,br,pb,4,8
            cd,cr,ce,4,1,5,4,ne,7,3,8,4
            fo
            gf,gh,gv,gg
            ks,kd,kl
            sa,sx,sr,4,5
            sdr,svd,3,2,4,3,ja
            ssfrt,styi
            sfc,sfb,smaa



            p.s. I don't like the fact that foo needs to map list twice but otherwise the order is wrong.






            share|improve this answer












            Not very pretty but shorter:



            foo // ClearAll
            foo[list_List] := Module[res
            , Sow @ MapIndexed[ If[ListQ @ #, Append[#2, Length @ #], #] &, list]
            ; foo /@ list;
            ]

            Column @ Reap[foo@list][[-1, 1]]



            ab,ad,3,4,aw
            be,br,pb,4,8
            cd,cr,ce,4,1,5,4,ne,7,3,8,4
            fo
            gf,gh,gv,gg
            ks,kd,kl
            sa,sx,sr,4,5
            sdr,svd,3,2,4,3,ja
            ssfrt,styi
            sfc,sfb,smaa



            p.s. I don't like the fact that foo needs to map list twice but otherwise the order is wrong.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 hours ago









            Kuba♦

            100k11195494




            100k11195494











            • It's just the kind of solution I was looking for, that makes me study deeply your foo, Thank you, Eskerrik asko
              – Anxon Pués
              2 hours ago
















            • It's just the kind of solution I was looking for, that makes me study deeply your foo, Thank you, Eskerrik asko
              – Anxon Pués
              2 hours ago















            It's just the kind of solution I was looking for, that makes me study deeply your foo, Thank you, Eskerrik asko
            – Anxon Pués
            2 hours ago




            It's just the kind of solution I was looking for, that makes me study deeply your foo, Thank you, Eskerrik asko
            – Anxon Pués
            2 hours ago










            up vote
            1
            down vote













            tdl = Extract[#, Sort @ Position[#, _List], 
            Replace[#, x_List :> Flatten[Position[#, x], Length @ x], 1] &] &;

            tdl @ list // Column // TeXForm



            $beginarrayl
            textab,textad,3,4,textaw \
            textbe,textbr,textpb,4,8 \
            textcd,textcr,textce,4,1,5,4,textne,7,3,8,4 \
            textfo \
            textgf,textgh,textgv,textgg \
            textks,textkd,textkl \
            textsa,textsx,textsr,4,5 \
            textsdr,textsvd,3,2,4,3,textja \
            textssfrt,textstyi \
            textsfc,textsfb,textsmaa \
            endarray$







            share|improve this answer
























              up vote
              1
              down vote













              tdl = Extract[#, Sort @ Position[#, _List], 
              Replace[#, x_List :> Flatten[Position[#, x], Length @ x], 1] &] &;

              tdl @ list // Column // TeXForm



              $beginarrayl
              textab,textad,3,4,textaw \
              textbe,textbr,textpb,4,8 \
              textcd,textcr,textce,4,1,5,4,textne,7,3,8,4 \
              textfo \
              textgf,textgh,textgv,textgg \
              textks,textkd,textkl \
              textsa,textsx,textsr,4,5 \
              textsdr,textsvd,3,2,4,3,textja \
              textssfrt,textstyi \
              textsfc,textsfb,textsmaa \
              endarray$







              share|improve this answer






















                up vote
                1
                down vote










                up vote
                1
                down vote









                tdl = Extract[#, Sort @ Position[#, _List], 
                Replace[#, x_List :> Flatten[Position[#, x], Length @ x], 1] &] &;

                tdl @ list // Column // TeXForm



                $beginarrayl
                textab,textad,3,4,textaw \
                textbe,textbr,textpb,4,8 \
                textcd,textcr,textce,4,1,5,4,textne,7,3,8,4 \
                textfo \
                textgf,textgh,textgv,textgg \
                textks,textkd,textkl \
                textsa,textsx,textsr,4,5 \
                textsdr,textsvd,3,2,4,3,textja \
                textssfrt,textstyi \
                textsfc,textsfb,textsmaa \
                endarray$







                share|improve this answer












                tdl = Extract[#, Sort @ Position[#, _List], 
                Replace[#, x_List :> Flatten[Position[#, x], Length @ x], 1] &] &;

                tdl @ list // Column // TeXForm



                $beginarrayl
                textab,textad,3,4,textaw \
                textbe,textbr,textpb,4,8 \
                textcd,textcr,textce,4,1,5,4,textne,7,3,8,4 \
                textfo \
                textgf,textgh,textgv,textgg \
                textks,textkd,textkl \
                textsa,textsx,textsr,4,5 \
                textsdr,textsvd,3,2,4,3,textja \
                textssfrt,textstyi \
                textsfc,textsfb,textsmaa \
                endarray$








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 10 mins ago









                kglr

                162k8187386




                162k8187386



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f182789%2flist-of-lists-of-lists-how-to-make-a-map-recursively%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    Installing NextGIS Connect into QGIS 3?

                    One-line joke