1
$\begingroup$

Problem. I work with a list and want to get the first element. For specific reasons I want to use # in combination with Map

For example

 data = {{1, 1, 1}, {2, 1, 2}, {1, 2, 3}, {3, 1, 4}, {1, 3, 5}};

the desired output is {1, 1, 1}

a simple way to do is using First like

First[data]

But I want to use # in combination of /@

When I use

#[[1]] & /@ lijst

the output is

{1, 2, 1, 3, 1}

The desired output is

{1, 1, 1}

Who has a suggestion

$\endgroup$
6
  • 2
    $\begingroup$ try #[[1]] &@data or # & @@ data? $\endgroup$
    – kglr
    May 23 at 19:45
  • 7
    $\begingroup$ if you have to use Map, try #[[1]] & /@ Transpose[data] $\endgroup$
    – kglr
    May 23 at 19:47
  • 4
    $\begingroup$ I’m voting to close this question because I don't see much practical utility associated with it. I could, of course, be wrong. $\endgroup$
    – Syed
    May 24 at 3:46
  • $\begingroup$ This question makes little sense indeed. On one hand you would like to apply a function to each element (Map), on the other hand, you only like data from the first element; seems contradictory. $\endgroup$
    – SHuisman
    May 24 at 12:23
  • $\begingroup$ It makes sense if you use a RotationTransform on a list and you need the first element as part of a transformation. $\endgroup$ May 24 at 12:37

0

Browse other questions tagged or ask your own question.