Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
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?

share|improve this question
1  
Why not {First[#], Last[#]} & /@ list ? –  b.gatessucks Jun 12 '13 at 6:09
    
@b.gatessucks yes, me silly, haha, you can post that as one answer. –  HyperGroups Jun 12 '13 at 6:10
3  
To properly use Through[]: Through[{First, Last}[#]] & /@ list. Slot-free version: Composition[Through, {First, Last}] /@ list. –  J. M. Jun 12 '13 at 6:19
1  
I didn't ask you to delete the question; I asked you if you could write an answer to your question (answering your own question is acceptable in this site, in case that wasn't made clear to you.) You can stand to gain rep from upvotes to your answer, and we can critique your understanding of the matter at hand. –  J. M. Jun 12 '13 at 6:46
4  
Are you aware that you can do this with Part? list[[All,{1,-1}]] –  Simon Woods Jun 12 '13 at 7:45

1 Answer 1

up vote 7 down vote accepted

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]} *)
share|improve this answer
    
Well done. ${}$ –  J. M. Jun 12 '13 at 7:21
2  
Please don't make this an orgy of different formatting styles... –  rm -rf Jun 12 '13 at 8:34
    
@rm-rf hi,Do you mean the <kbd>tag? I'm learning format in SE, Do you think the hint word Output is necessary? –  HyperGroups Jun 12 '13 at 8:37
    
@HyperGroups nice answer (+1). The <kbd> tag stands for keyboard, which is usually used for indicating a key on the keyboard, e.g., <kbd>Ctrl</kbd>. 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 8:52
    
@Silvia Ok, I learned that. –  HyperGroups Jun 12 '13 at 8:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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