List of lists of lists how to make a map recursively
Clash 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
list-manipulation
add a comment |Â
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
list-manipulation
add a comment |Â
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
list-manipulation
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
list-manipulation
edited 2 hours ago
That Gravity Guy
1,079512
1,079512
asked 3 hours ago
Anxon Pués
429211
429211
add a comment |Â
add a comment |Â
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.
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
add a comment |Â
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$
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
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$
add a comment |Â
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$
add a comment |Â
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$
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$
answered 10 mins ago
kglr
162k8187386
162k8187386
add a comment |Â
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%2f182789%2flist-of-lists-of-lists-how-to-make-a-map-recursively%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