3 added 195 characters in body
source | link
a = {{1.1, 2.2}, {1.1, 2.2}, {x, b}, {c, d}, {x, b}, {1, 2}}

# /. (Rule[First@#, Append @@ #] & /@ Tally[#]) &[a]

(*
{{1.1, 2.2, 2}, {1.1, 2.2, 2}, {x, b, 2}, {c, d, 1}, {x, b, 2}, {1, 2,1}}
*)

For huge lists:

# /. Dispatch[Rule[First@#, Append @@ #] & /@ Tally[#]] &[a];

Will speed things up nicely.

Also quite fast on large lists:

Partition[Flatten[Riffle[#, Join @@ ConstantArray @@@ Tally[#][[All, {2, 2}]]]], 3] &@a

Unlike the above (where order of elements does not matter), this takes advantage of the OP assumptions of same elements appearing in sequence.

Even faster on large arrays:

Block[{tmp = ArrayPad[#, {{0, 0}, {0, 1}}], t = Tally[#]},
       tmp[[All, 3]] = Join @@ ConstantArray @@@ t[[All, {2, 2}]];
       tmp] &[data]
a = {{1.1, 2.2}, {1.1, 2.2}, {x, b}, {c, d}, {x, b}, {1, 2}}

# /. (Rule[First@#, Append @@ #] & /@ Tally[#]) &[a]

(*
{{1.1, 2.2, 2}, {1.1, 2.2, 2}, {x, b, 2}, {c, d, 1}, {x, b, 2}, {1, 2,1}}
*)

For huge lists:

# /. Dispatch[Rule[First@#, Append @@ #] & /@ Tally[#]] &[a];

Will speed things up nicely.

Also quite fast on large lists:

Partition[Flatten[Riffle[#, Join @@ ConstantArray @@@ Tally[#][[All, {2, 2}]]]], 3] &@a

Unlike the above (where order of elements does not matter), this takes advantage of the OP assumptions of same elements appearing in sequence.

a = {{1.1, 2.2}, {1.1, 2.2}, {x, b}, {c, d}, {x, b}, {1, 2}}

# /. (Rule[First@#, Append @@ #] & /@ Tally[#]) &[a]

(*
{{1.1, 2.2, 2}, {1.1, 2.2, 2}, {x, b, 2}, {c, d, 1}, {x, b, 2}, {1, 2,1}}
*)

For huge lists:

# /. Dispatch[Rule[First@#, Append @@ #] & /@ Tally[#]] &[a];

Will speed things up nicely.

Also quite fast on large lists:

Partition[Flatten[Riffle[#, Join @@ ConstantArray @@@ Tally[#][[All, {2, 2}]]]], 3] &@a

Unlike the above (where order of elements does not matter), this takes advantage of the OP assumptions of same elements appearing in sequence.

Even faster on large arrays:

Block[{tmp = ArrayPad[#, {{0, 0}, {0, 1}}], t = Tally[#]},
       tmp[[All, 3]] = Join @@ ConstantArray @@@ t[[All, {2, 2}]];
       tmp] &[data]
2 added 274 characters in body
source | link
a = {{1.1, 2.2}, {1.1, 2.2}, {x, b}, {c, d}, {x, b}, {1, 2}}

# /. (Rule[First@#, Append @@ #] & /@ Tally[#]) &[a]

(*
{{1.1, 2.2, 2}, {1.1, 2.2, 2}, {x, b, 2}, {c, d, 1}, {x, b, 2}, {1, 2,1}}
*)

For huge lists:

# /. Dispatch[Rule[First@#, Append @@ #] & /@ Tally[#]] &[a];

Will speed things up nicely.

Also quite fast on large lists:

Partition[Flatten[Riffle[#, Join @@ ConstantArray @@@ Tally[#][[All, {2, 2}]]]], 3] &@a

Unlike the above (where order of elements does not matter), this takes advantage of the OP assumptions of same elements appearing in sequence.

a = {{1.1, 2.2}, {1.1, 2.2}, {x, b}, {c, d}, {x, b}, {1, 2}}

# /. (Rule[First@#, Append @@ #] & /@ Tally[#]) &[a]

(*
{{1.1, 2.2, 2}, {1.1, 2.2, 2}, {x, b, 2}, {c, d, 1}, {x, b, 2}, {1, 2,1}}
*)

For huge lists:

# /. Dispatch[Rule[First@#, Append @@ #] & /@ Tally[#]] &[a];

Will speed things up nicely.

a = {{1.1, 2.2}, {1.1, 2.2}, {x, b}, {c, d}, {x, b}, {1, 2}}

# /. (Rule[First@#, Append @@ #] & /@ Tally[#]) &[a]

(*
{{1.1, 2.2, 2}, {1.1, 2.2, 2}, {x, b, 2}, {c, d, 1}, {x, b, 2}, {1, 2,1}}
*)

For huge lists:

# /. Dispatch[Rule[First@#, Append @@ #] & /@ Tally[#]] &[a];

Will speed things up nicely.

Also quite fast on large lists:

Partition[Flatten[Riffle[#, Join @@ ConstantArray @@@ Tally[#][[All, {2, 2}]]]], 3] &@a

Unlike the above (where order of elements does not matter), this takes advantage of the OP assumptions of same elements appearing in sequence.

1
source | link

a = {{1.1, 2.2}, {1.1, 2.2}, {x, b}, {c, d}, {x, b}, {1, 2}}

# /. (Rule[First@#, Append @@ #] & /@ Tally[#]) &[a]

(*
{{1.1, 2.2, 2}, {1.1, 2.2, 2}, {x, b, 2}, {c, d, 1}, {x, b, 2}, {1, 2,1}}
*)

For huge lists:

# /. Dispatch[Rule[First@#, Append @@ #] & /@ Tally[#]] &[a];

Will speed things up nicely.