2

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!

Lazer
  • 77
  • 3
  • 1
    How about First@Cases[list, "C", Infinity]? – march Mar 08 '17 at 18:13
  • @march Yes, it works, thanks! But what the 'Infinity' is doing here, does it represent 'all levels'? (but I tried several number instead, which doesn't work, so I guess it has a different meaning?) And is '@' the same as '@@'? Sorry I'm just a beginner in Mathematica.. – Lazer Mar 08 '17 at 18:23
  • 1
    For the symbols, see here. The 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 to level. If you do First@Cases[list, "C", 6], it returns "C", but not if you put 5 in place of 6. – march Mar 08 '17 at 18:28
  • @march Thanks so much! I was just struggling with all those symbols – Lazer Mar 08 '17 at 18:31

2 Answers2

3
list[[3, Sequence @@ ConstantArray[1, 5]]]

"C"

kglr
  • 394,356
  • 18
  • 477
  • 896
1

Since V 13.1 there is a new variant of Splice:

list[[3, Splice[Table[1, 5], Part]]]

C

Since Splice expressions do not automatically flatten inside heads other than List we had to give Part as 2nd argument.

eldo
  • 67,911
  • 5
  • 60
  • 168