# Select elements from a list of of couples [closed]

I have a list which looks like

 a={{0., 2.}, {0.2, 1.96041}, {0.4, 1.9216}, {0.6, 1.88355}, {0.8, 1.8463},...}

and I want to select all the n^th couples contained in another list,

 b={1, 3, 6, 7, 9,...}

so in this case I need to extract the first, third... couples. How can I do?

• Try a[[b]]? (Part)
– kglr
Commented Sep 8, 2021 at 9:08
• Yeah, that was it... Thanks! Commented Sep 8, 2021 at 9:21
• @kglr to my taste, this is the best answer because it's simple Commented Sep 8, 2021 at 10:11

You can also use Extract. Two pieces of code below should generate the same result.

Extract[a, #] & /@ b
Extract[a, {b}\[Transpose]]


Following the lead from kglr's answer in the comments and noticing your b list:

Example:

alist = a = {{0., 2.}, {0.2, 1.96041}, {0.4, 1.9216}, {0.6,
1.88355}, {0.8, 1.8463}}
blist = {1, 7, 9, 2}


Notice that Parts 7,9 are not present and the following will complain.

alist[[blist]]


A slight improvement would be to filter the indices in blist that are (currently?) larger than the length of the alist.

Part[alist, Select[blist, # <= Length@alist & ]]


OR

alist[[Select[blist, # <= Length@alist & ]]]


It may or may not be important for your app. The ... and your current choice of indices for the b got me thinking.

{{0., 2.}, {0.2, 1.96041}}