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

Replacing whitespace in a list with comma and turning into sublists

$
0
0

I have the following list:

l={"1 atattaggtt tttacctacc caggaaaagc caaccaacct61 ctctaaacga actttaaaat ctgtgtagct gtcgctcggc121 gcagtataaa caataataaa"}

which I want to turn into:

{{{1,{"atattaggtt","tttacctacc","caggaaaagc","caaccaacct"}},    {61,{"ctctaaacga","actttaaaat","ctgtgtagct","gtcgctcggc"}},    {121,{"gcagtataaa","caataataaa"}}}

I wonder how one does this?

Update: I know that StringReplace[l, WhitespaceCharacter -> ","] gives me:

{"1,atattaggtt,tttacctacc,caggaaaagc,caaccaacct,61,ctctaaacga,\actttaaaat,ctgtgtagct,gtcgctcggc,121,gcagtataaa,caataataaa"}

Yet I don't know how to sublist this as above.


Viewing all articles
Browse latest Browse all 186

Trending Articles



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