Skip to main content
added 404 characters in body
Source Link
user1066
  • 22.7k
  • 3
  • 36
  • 59
SequenceSplit[list, {a_, b_, c_} :> {{a, b}, c}]

(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapApply[{{#1, #2}, #3} &]@Partition[list, 3]

 (* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapThread[{{#1, #2}, #3} &, Transpose@Partition[list, 3]]


(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

In addition, using the undocumented (but very useful) fifth argument of Padding

Partition[list, 3, 3, 1, {}, {{#1, #2}, #3} &]

(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *) 

Just for fun

Using Map to replace the Head List in the partitioned list with a 'pure' function:

Map[Replace[List :> ({{#1, #2}, #3} &)], 
    Partition[list, 3], {2}, Heads -> True]

(* {{a, b, c}, {a, b, d}, {a, b, e}, {a, b, f}, {a, b, g}} *)

A similar approach using MapAt

MapAt[Replace[List :> ({{#1, #2}, #3} &)], 
    Partition[list, 3], {All, 0}]
SequenceSplit[list, {a_, b_, c_} :> {{a, b}, c}]

(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapApply[{{#1, #2}, #3} &]@Partition[list, 3]

 (* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapThread[{{#1, #2}, #3} &, Transpose@Partition[list, 3]]


(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

In addition, using the undocumented (but very useful) fifth argument of Padding

Partition[list, 3, 3, 1, {}, {{#1, #2}, #3} &]

(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *) 
SequenceSplit[list, {a_, b_, c_} :> {{a, b}, c}]

(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapApply[{{#1, #2}, #3} &]@Partition[list, 3]

 (* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapThread[{{#1, #2}, #3} &, Transpose@Partition[list, 3]]


(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

In addition, using the undocumented (but very useful) fifth argument of Padding

Partition[list, 3, 3, 1, {}, {{#1, #2}, #3} &]

(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *) 

Just for fun

Using Map to replace the Head List in the partitioned list with a 'pure' function:

Map[Replace[List :> ({{#1, #2}, #3} &)], 
    Partition[list, 3], {2}, Heads -> True]

(* {{a, b, c}, {a, b, d}, {a, b, e}, {a, b, f}, {a, b, g}} *)

A similar approach using MapAt

MapAt[Replace[List :> ({{#1, #2}, #3} &)], 
    Partition[list, 3], {All, 0}]
added 221 characters in body
Source Link
user1066
  • 22.7k
  • 3
  • 36
  • 59
SequenceSplit[list, {a_, b_, c_} :> {{a, b}, c}]

(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapApply[{{#1, #2}, #3} &]@Partition[list, 3]

 (* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapThread[{{#1, #2}, #3} &, Transpose@Partition[list, 3]]


(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

In addition, using the undocumented (but very useful) fifth argument of Padding

Partition[list, 3, 3, 1, {}, {{#1, #2}, #3} &]

(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *) 
SequenceSplit[list, {a_, b_, c_} :> {{a, b}, c}]

(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapApply[{{#1, #2}, #3} &]@Partition[list, 3]

 (* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapThread[{{#1, #2}, #3} &, Transpose@Partition[list, 3]]


(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)
SequenceSplit[list, {a_, b_, c_} :> {{a, b}, c}]

(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapApply[{{#1, #2}, #3} &]@Partition[list, 3]

 (* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapThread[{{#1, #2}, #3} &, Transpose@Partition[list, 3]]


(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

In addition, using the undocumented (but very useful) fifth argument of Padding

Partition[list, 3, 3, 1, {}, {{#1, #2}, #3} &]

(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *) 
added 141 characters in body
Source Link
user1066
  • 22.7k
  • 3
  • 36
  • 59
SequenceSplit[list, {a_, b_, c_} :> {{a, b}, c}]

(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapApply[{{#1, #2}, #3} &]@Partition[list, 3]

 (* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapThread[{{#1, #2}, #3} &, Transpose@Partition[list, 3]]


(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)
MapApply[{{#1, #2}, #3} &]@Partition[list, 3]


(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)
SequenceSplit[list, {a_, b_, c_} :> {{a, b}, c}]

(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapApply[{{#1, #2}, #3} &]@Partition[list, 3]

 (* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)

Or

MapThread[{{#1, #2}, #3} &, Transpose@Partition[list, 3]]


(* {{{a, b}, c}, {{a, b}, d}, {{a, b}, e}, {{a, b}, f}, {{a, b}, g}} *)
Source Link
user1066
  • 22.7k
  • 3
  • 36
  • 59
Loading