# How to specify Part in [[{...}]] at mixed levels?

In the following example, how to easily get {2,4,10} using the [[{...}]] syntax?

aa = {2, 4, 6, {8, 10, 12}, 14, 16, 18, 20};
aa[[{1, 2}]]
(*{2,4}*)
aa[[{1, 2(* what to put here?? *)}]]
(*{2,4,10}*)
aa[[{1, 2(* what to put here?? *)}]]
(*{2,4,{10,12}}*)

• As far as I know, that's not possible with Part. Use Extract instead: Extract[aa, {{1}, {2}, {4, 2}}]. Feb 12, 2020 at 22:13
• if one is allowed to use Flatten, then Flatten[{aa[[{1, 2}]], aa[[{1, 2, 4}]][[3, 2]]}] gives {2, 4, 10} but I would also use Extract, much simpler. Feb 12, 2020 at 22:24
• Join[aa[[{1, 2}]], {aa[[4, 2]]}] Feb 13, 2020 at 0:20
• aa[[##]]&@@@ {1,2, {4, 2}} after Bob Hanlon here Feb 13, 2020 at 0:20
• As @HenrikSchumacher noted: Part is not the right tool for the job here; it cannot mix and match levels in this way. Extract is the correct function for this. Feb 13, 2020 at 12:34

Try this:

Part[Flatten[aa], #] & /@ {1, 2, 5}

(*  {2, 4, 10}  *)


If you need to first determine the positions of the desired elements do first

pos = Position[Flatten[aa], #] & /@ {2, 4, 10} // Flatten

(* {1, 2, 5}  *)


and then

Part[Flatten[aa], #] & /@ pos

(*  {2, 4, 10}   *)


Have fun!