Quantcast
Channel: Active questions tagged string-manipulation - Mathematica Stack Exchange
Viewing all articles
Browse latest Browse all 200

List rearrangment with joining of strings

$
0
0

I have a list of strings:

lis = {{"a","b","x"},{"d","e","y"},{"a","b","z"},{"d","c","x"},{"a","b","w"}}

I would like to use StringJoin on the last elements where initial elements are the same to obtain:

res = {{"a","b","xzw"},{"d","e","y"},{"d","c","x"}}

Doing:

lis = SortBy[lis, {#[[1]]} &]SequenceCases[lis, {{a_, b_, c_}, {a_, b_, d_}} :> {a, b, StringJoin[c, d]}]

only gives:

{{"a", "b", "wx"}}

Thanks for any suggestions.


Viewing all articles
Browse latest Browse all 200

Trending Articles



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