3
list = Partition[Range[20], 5, 5, 1, {}]
{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}}
pos = Transpose[{Through[First, Last] /@ list, Through[Last, First] /@ list}]
{{1, 5}, {6, 10}, {11, 15}, {16, 20}}

As you see, I've used Through twice. I think once should be enough, but I haven't been able to see how to do it with one Through. Any ideas?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
HyperGroups
  • 8,619
  • 1
  • 26
  • 63

1 Answers1

7

I have tried this

list = Partition[Range[20], 5, 5, 1, {}];
Through[{First, Last}] /@ list
(* {Through[{First,Last}][{1,2,3,4,5}],Through[{First,Last}][{6,7,8,9,10}],
    Through[{First,Last}][{11,12,13,14,15}],Through[{First,Last}][{16,17,18,19,20}]} *)

Let's see the example in help page of Through

Through[{f, g, h}[x]]   
(* {f[x],g[x],h[x]} *)

as @0x4A4D metioned in the comment. We need one argument for

Through[{First, Last}[#]] & /@ list
(* {{1,5},{6,10},{11,15},{16,20}} *)

this is one error usage

Through[{f, g, h}][x]
(* Through[{f,g,h}][x] *)

Through[{f, g, h}[#]] &[x]
(* {f[x],g[x],h[x]} *)
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
HyperGroups
  • 8,619
  • 1
  • 26
  • 63
  • 2
    Please don't make this an orgy of different formatting styles... – rm -rf Jun 12 '13 at 08:34
  • @rm-rf hi,Do you mean the tag? I'm learning format in SE, Do you think the hint word Output is necessary? – HyperGroups Jun 12 '13 at 08:37
  • @HyperGroups nice answer (+1). The <kbd> tag stands for keyboard, which is usually used for indicating a key on the keyboard, e.g., Ctrl. So it may not be a best choice for "Output". In fact, on this site, people usually just put the output results in blockquotes without any "hint word". – Silvia Jun 12 '13 at 08:52
  • @Silvia Ok, I learned that. – HyperGroups Jun 12 '13 at 08:57
  • @HyperGroups Yes, that, but also several other things that I've noticed from other posts. 1) There is no need to repeat the question title in <h1> or to have a heading "My answer", because both are clear from the context. 2) Please do not use <pre> — when you asked me earlier, I was referring to its use in some tricky situations (very rare). You're indenting by 4 and using <pre>, which messes up the layout. Please learn how to indent using markdown instead (hundreds of thousands of users across the SE network have no problem with it...). [continued...] – rm -rf Jun 12 '13 at 10:11
  • <kbd> tags should be used for indicating keys on a keyboard. 4) The quote block is being heavily abused (not just by you). While sometimes it is justified, I disagree with its use for output (although I can't do much about it). I prefer the alternate convention of commenting out the output (like I did in my edit above), because then you can simply copy the block and run in Mathematica and you won't run into issues. Also, output in code within blockquote will mess with this API based code extractor, since is is inserted in an input cell.
  • – rm -rf Jun 12 '13 at 10:12
  • @rm-rf I agree that using (*...*) would be more convenient for copying the whole code block all at once. But about the extractor, please see my comment. :) – Silvia Jun 12 '13 at 11:37
  • @rm-rf fine, I'll take some suggestions. – HyperGroups Jun 12 '13 at 12:06