I have a list,
list={"A","B",{{{{{"C"}}}}}, D, E , F , G}
and I want to choose the 'C' (i.e. the first element in the sixth level of the third element in 'list'), which is
list[[3, 1, 1, 1, 1, 1]]
and this gives
C
My question is how can I change the five '1' into a shorter way (use 'i' or something).
I tried
list[[3, ConstantArray[1, 5]]]
I know this is probably wrong because the ConstantArray gives a list, but it gives
{{{{{"C"}}}}, {{{{"C"}}}}, {{{{"C"}}}}, {{{{"C"}}}}, {{{{"C"}}}}}
Why is that?
And how can I make it right?
And in general, how can we make a sequence of repeated numbers, like 1,1,1,1,1 not in a list format (without {})?
Thanks for help!
First@Cases[list, "C", Infinity]
? $\endgroup$Infinity
means to search on all levels (except level 0, I think). In general,Cases[expr, patt, level]
means to search on all levels down tolevel
. If you doFirst@Cases[list, "C", 6]
, it returns"C"
, but not if you put 5 in place of 6. $\endgroup$