2
$\begingroup$

How can I retrieve an element of a list, specifying the position of the desired element as another list? For instance, I like to get list[[2,1]] but all I have is pos = {2,1}. I want something like list[[pos]] or list@@pos and not list[[pos[[1]],pos[[2]]]] or Extract[list,pos] (unless there is a shorhand for Extract).

$\endgroup$
  • 5
    $\begingroup$ list[[##]]&@@pos. $\endgroup$ – Alexey Popkov Jun 22 '17 at 23:06
  • 4
    $\begingroup$ Extract[list, {2,1}]. Why not use this one? $\endgroup$ – march Jun 22 '17 at 23:24
  • 1
    $\begingroup$ @AlexeyPopkov, doesn't work for multidimensional arrays. $\endgroup$ – Miladiouss Jun 22 '17 at 23:27
  • $\begingroup$ What about Part[list, #1, #2]&@@pos? $\endgroup$ – Riccardo Cazzin Jun 22 '17 at 23:31
  • 2
    $\begingroup$ I mean, a "shorthand" for Extract could be list~Extract~pos. $\endgroup$ – march Jun 23 '17 at 0:33
3
$\begingroup$
SeedRandom[42]; m = RandomInteger[10, {4, 2}]

{{6, 0}, {8, 2}, {0, 0}}

m[[##]] & @@ {2, 1}

8

|improve this answer|||||
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.