Skip to main content
1 of 5
HyperGroups
  • 8.6k
  • 1
  • 26
  • 63

How to extract the element in the middle position of one list

Here is one sample code, seems a little too long:

extract[x_]:=Part[x,If[IntegerQ[#],{#},{Floor[#],Ceiling[#]}]&@Median[Range[Length@x]]]

Here is another, shorter. But for Even list, it only gives one value, not two. I think two values for even list is much better in some sense.

extract[x_]:=Part[x,Quantile[Range[Length@x],1/2]]

So is there any consice code or efficient method?

HyperGroups
  • 8.6k
  • 1
  • 26
  • 63