Quantcast
Channel: Adding elements to some sublists of unequal length - Mathematica Stack Exchange
Viewing all articles
Browse latest Browse all 7

Answer by eldo for Adding elements to some sublists of unequal length

$
0
0

From the Association universe:

KeyValueMap[Flatten @* List] @ Merge[# &] @ Map[GroupBy[First -> Rest], {a, b}]

{{1, 3, 5, 2}, {2, 6, 2, 1}, {3, 5, 6, 1, 2}, {4, 2, 3}}

Or

KeyValueMap[Flatten @* List] @ Merge[# &] @ MapApply[#1 -> {##2} &, Join[a, b]]

{{1, 3, 5, 2}, {2, 6, 2, 1}, {3, 5, 6, 1, 2}, {4, 2, 3}}


Viewing all articles
Browse latest Browse all 7

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>