Note that there are some explanatory texts on larger screens.

plurals
  1. POErlang - Split a list into lists based on value
    primarykey
    data
    text
    <p>I am trying to split this list</p> <pre><code>List = [[&lt;&lt;"5"&gt;&gt;, &lt;&lt;"54"&gt;&gt;], [&lt;&lt;"00"&gt;&gt;], [&lt;&lt;"35"&gt;&gt;, &lt;&lt;"54"&gt;&gt;, &lt;&lt;"45"&gt;&gt;, &lt;&lt;"55"&gt;&gt;], [&lt;&lt;"00"&gt;&gt;],[ &lt;&lt;"5"&gt;&gt;]] </code></pre> <p>into </p> <pre><code>List = [[&lt;&lt;"5"&gt;&gt;, &lt;&lt;"54"&gt;&gt;], [&lt;&lt;"35"&gt;&gt;, &lt;&lt;"54"&gt;&gt;, &lt;&lt;"45"&gt;&gt;, &lt;&lt;"55"&gt;&gt;], [&lt;&lt;"5"&gt;&gt;]] </code></pre> <p>Basically based on the &lt;&lt;"00">></p> <p>What is the best BIF to go about this, I have some code, but its sloppy, and Im trying to learn.</p> <p>Thanks</p> <p>EDIT:</p> <p>Tried the following, does not work</p> <p>Done2 = lists:splitwith( [&lt;&lt;"00">>], Done1),</p> <p>EDIT: This Line works!</p> <pre><code>7&gt; lists:splitwith(fun(A) -&gt; A == [&lt;&lt;"00"&gt;&gt;] end, List). {[], [[&lt;&lt;"5"&gt;&gt;,&lt;&lt;"54"&gt;&gt;], [&lt;&lt;"00"&gt;&gt;], [&lt;&lt;"35"&gt;&gt;,&lt;&lt;"54"&gt;&gt;,&lt;&lt;"45"&gt;&gt;,&lt;&lt;"55"&gt;&gt;], [&lt;&lt;"00"&gt;&gt;], [&lt;&lt;"5"&gt;&gt;]]} </code></pre> <p>However I need something a little more complicated: like when the delim is [&lt;&lt;"00">>,&lt;&lt;"23">>]</p> <pre><code>9&gt; List = [[&lt;&lt;"5"&gt;&gt;,&lt;&lt;"54"&gt;&gt;], [&lt;&lt;"00"&gt;&gt;,&lt;&lt;"23"&gt;&gt;], [&lt;&lt;"35"&gt;&gt;,&lt;&lt;"54"&gt;&gt;], [&lt;&lt;"5"&gt; &gt;], [&lt;&lt;"00"&gt;&gt;, &lt;&lt;"23"&gt;&gt;]]. [[&lt;&lt;"5"&gt;&gt;,&lt;&lt;"54"&gt;&gt;], [&lt;&lt;"00"&gt;&gt;,&lt;&lt;"23"&gt;&gt;], [&lt;&lt;"35"&gt;&gt;,&lt;&lt;"54"&gt;&gt;], [&lt;&lt;"5"&gt;&gt;], [&lt;&lt;"00"&gt;&gt;,&lt;&lt;"23"&gt;&gt;]] 10&gt; lists:splitwith(fun(A) -&gt; A == [&lt;&lt;"00"&gt;&gt;] end, List). {[], [[&lt;&lt;"5"&gt;&gt;,&lt;&lt;"54"&gt;&gt;], [&lt;&lt;"00"&gt;&gt;,&lt;&lt;"23"&gt;&gt;], [&lt;&lt;"35"&gt;&gt;,&lt;&lt;"54"&gt;&gt;], [&lt;&lt;"5"&gt;&gt;], [&lt;&lt;"00"&gt;&gt;,&lt;&lt;"23"&gt;&gt;]]} 11&gt; lists:splitwith(fun(A) -&gt; A == [&lt;&lt;"00"&gt;&gt;,&lt;&lt;"23"&gt;&gt;] end, List). {[], [[&lt;&lt;"5"&gt;&gt;,&lt;&lt;"54"&gt;&gt;], [&lt;&lt;"00"&gt;&gt;,&lt;&lt;"23"&gt;&gt;], [&lt;&lt;"35"&gt;&gt;,&lt;&lt;"54"&gt;&gt;], [&lt;&lt;"5"&gt;&gt;], [&lt;&lt;"00"&gt;&gt;,&lt;&lt;"23"&gt;&gt;]]} 12&gt; </code></pre> <p>No luck there</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload