I have a string list:
lis = {"abc","def","def ghi","jkl","ghi","jkl"}
I have another string list whose elements contain two members of lis
joined together and separated by a space character:
lis2 = {"abc jkl","def ghi ghi","jkl abc"}
I would like to separate each member of lis2
back into its two components that belong to lis
:
res = {{"abc","jkl"},{"def ghi","ghi"},{"jkl","abc"}}
As always, thanks for any ideas.
Here is another sample data set that may state the problem more clearly.
newLis = {"Texas State","Ohio","Sam Houston State","Ohio State"}
newLis2 = {{"Texas","State","Ohio","State"},{"Sam","Houston","State","Ohio","State"},{"Ohio","Sam","Houston","State"}}
Each of the three elements of newLis2 needs to be decomposed into two elements which are members of newLis:
newRes = {{"Texas State","Ohio State"},{"Sam Houston State","Ohio State"},{"Ohio","Sam Houston State"}}
*Please see kglr's comment below, he clearly states the problem at (1). It is best not to make the responders have to guess at the questioner's question :/ *
StringSplit /@ lis2
is your after? $\endgroup$ – yode Sep 13 '18 at 2:38lis
) , and (2) reorganize andStringJoin
a list of strings so that the resulting strings match the ones in the references list (lis
). $\endgroup$ – kglr Sep 13 '18 at 5:30