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.

This question already has an answer here:

I know riffle will combine the lists {1,2,3} and {a,b,c} to be {1,a,2,b,3,c}. Is there a way to work backward and split the list {a,b,c,d,e,f} to be {a,c,e} and {b,d,f}?

share|improve this question

marked as duplicate by Mr.Wizard Jun 2 at 21:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
{a,b,c,d,e,f}[[#;;;;2]]&/@{1,2} –  belisarius Jun 2 at 13:51
2  
Transpose[Partition[{a, b, c, d, e, f}, 2]] –  nikie Jun 2 at 13:54
    
@belisarius (& nikie) Why don't you post an answer? –  Szabolcs Jun 2 at 13:54
    
@Szabolcs b/c I don't fully understand the question. Specifically, what has Riffle[] to do with Part[]? –  belisarius Jun 2 at 13:56
    
@belisarius As I understand it (based on the example, which seems clear), yours is a good solution. Get back x and y from the result of Riffle[x,y], provided that x and y are of the same length. –  Szabolcs Jun 2 at 13:58
show 1 more comment

2 Answers 2

You may want to try

ClearAll[unRiffle];
unRiffle[{}] = {{}, {}};
unRiffle[x_List] := x[[# ;; ;; 2]] & /@ {1, 2}
{lOdd, lEven} = unRiffle[{a, b, c, d, e, f}]
(*
 {{a, c, e}, {b, d, f}}
*)
share|improve this answer
1  
Bad alternative: Rest@Extract[list, {{}, {;; ;; 2}, {2 ;; ;; 2}}] –  Jacob Akkerboom Jun 2 at 14:18
add comment

Just for fun:

ClearAll[unRiffle];
unRiffle[{a_, l___}, {x___}, y_] := unRiffle[{l}, y, {x, a}];
unRiffle[{}, x_, y_] := {x, y};
unRiffle[l_List] := unRiffle[l, {}, {}];
share|improve this answer
add comment

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