How to convert a string into a list without including a specific character plus without using replace and split methods?
<p>Let's say you have:</p>

<pre><code>x = "1,2,13"
</code></pre>

<p>and you want to achieve:</p>

<pre><code>list = ["1","2","13"]
</code></pre>

<p>Can you do it without the split and replace methods?</p>

<p>What I have tried:</p>

<pre><code>list=[]
for number in x:
    if number != ",":
        list.append(number)

print(list) # ['1', '2', '1', '3']
</code></pre>

<p>but this works only if its a single digit</p>

<p>Here is a way using that assumes integers using <code>itertools</code>:</p>

<pre><code>&gt;&gt;&gt; import itertools
&gt;&gt;&gt; x = "1,88,22"
&gt;&gt;&gt; ["".join(g) for b,g in itertools.groupby(x,str.isdigit) if b]
['1', '88', '22']
&gt;&gt;&gt; 
</code></pre>

<p>Here is a method that uses traditional looping:</p>

<pre><code>&gt;&gt;&gt; digit = ""
&gt;&gt;&gt; digit_list = []
&gt;&gt;&gt; for c in x:
...   if c.isdigit():
...     digit += c
...   elif c == ",":
...     digit_list.append(digit)
...     digit = ""
... else:
...   digit_list.append(digit)
... 
&gt;&gt;&gt; digit_list
['1', '88', '22']
&gt;&gt;&gt; 
</code></pre>

<p>In the real world, you'd probably just use regex...</p>

python