3
$\begingroup$

I am given this problem.

planets = 
  {{Beta Pictoris B, D, {7, 1.6}}, 
   {WASP52B, T, {0.453, 1.270}}, 
   {Kepler426b, T, {1.0, 1.090}}, 
   {CoRoT6b, T, {2.95, 1.166}}, 
   {Kepler34b, R, {0.220, 0.784}}, 
   {Kepler367b, R, {0.0037, 0.116}}, 
   {Kepler200c, R, {0.0119, 0.142}}};

Q. Using the Mathematica function Map and a suitably chosen function, generate a new list containing only the names of the planets

I have done this using Extract, which works fine, but I'm not sure of how to do this with Map.

f = Table[Extract[planets, {i, 1}], {i, 1, 7}]
$\endgroup$
  • $\begingroup$ just use planets[[All, 1]] (see Part [[..]] in the docs) $\endgroup$ – kglr Jan 23 at 20:04
5
$\begingroup$

If you have to use Map:

Map[First, planets]

{B Beta Pictoris, WASP52B, Kepler426b, CoRoT6b, Kepler34b, Kepler367b, Kepler200c}

Otherwise, you can use Part [[..]]:

planets[[All, 1]]

{B Beta Pictoris, WASP52B, Kepler426b, CoRoT6b, Kepler34b, Kepler367b, Kepler200c}

$\endgroup$
0
$\begingroup$

A restatement of kglr's answer in mathematica shorthand:

#[[1]] & /@ planets
$\endgroup$
  • 3
    $\begingroup$ Or # & @@@ planets for shortshorthand... $\endgroup$ – ciao Jan 24 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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