How to modify .split function to to apply to different alpha numeric inputs?
<p>I have the following two types of input:</p>

<pre><code>## Case 1 (a)
# Input #1(a)
&gt;qrst
ABC 10 9 7
&gt;qqqq
ACC 2 5 3

# Case 1 (b) --&gt; Simplified form of Case 1(a)
# Input #1()
&gt;qrst
A 10
&gt;qqqq
A 2

# After reading in the file and making it a list I store the above in l
l = ['ABC 10 9 7', 'ACC 2 5 3'] # Case 1(a)
l = ['A 10', 'A 2'] # Case 1(b)

 #In the following code I split the alpha-numeric elements above and
 #create separate lists where I store the alphabets alone (in list "sequences") and 
 #numeric alone (in list "qualities")

ll = len(l)
all_inputs = [] 
for i in range(0,ll):
    sq = l[i]
    sequence = sq.split(" ")[0] ## Stores only the alphabets
    qualities = sq.split(" ")[1:] ## Stores only the numeric
    qualities = filter(None, qualities)
    for sub in sequence:
        if sub == "-":
            idx = list(sequence).index(sub)
            qualities.insert(idx,"0")  
    all_inputs.append((sequence, qualities))
    print 

   #Case1(a) Output reads currently reads as
   A   #print sequence
   ['2']  #print qualities
</code></pre>

<p>I encounter another type of input file as follows:</p>

<pre><code>## Case 2
 #  Input #2
 &gt;qrst
A    #No space after A

10
&gt;qqqq
A    #No space after A

2

Here 
l = ['A10', 'A2']

I use the same code as above

#Case2 Output reads currently reads as
A2 #print sequences
[] #print qualities
</code></pre>

<p>I need #Case 2 to also have the output
    A   #print sequence
    ['2']  #print qualities</p>

<p>How do I modify the code above such that it can accommodate both ['ABC 10 9 7', 'ACC 2 5 3'] or ['A 10','A 2'] or['A10','A2'] types of input file/ 'l'?
I need Case 2 to have the same output as Case 1(b), so that I can apply the same line of code later on. But remember, it has to be a generalized code for Case 1 and Case 2. </p>

<p>would this work:</p>

<pre><code>import re

input_seq = "A10 B   20 C30 D1 Z   67"
input_raw = re.split(r'([A-Z]) *(\d+)' , input_seq)
input_clean = [x for x in input_raw if x and not x.isspace()]
print zip(input_clean[::2], input_clean[1::2])
</code></pre>

<p><em>gives</em>:</p>

<pre><code>[('A', '10'), ('B', '20'), ('C', '30'), ('D', '1'), ('Z', '67')]
</code></pre>

<p>if you change the last expression:</p>

<pre><code>print [ "{} {}".format(*x) for x in zip(input_clean[::2], input_clean[1::2]) ]
</code></pre>

<p>you get:</p>

<pre><code>['A 10', 'B 20', 'C 30', 'D 1', 'Z 67']
</code></pre>

<p>alternatively, you can try normalizing the input:</p>

<pre><code>input_seq = "A10 B   20 C30 D1 Z   67"
print re.sub(r'([A-Z]) *(\d+)', r'\1 \2', input_seq)
</code></pre>

<p>this will print:</p>

<pre><code>A 10 B 20 C 30 D 1 Z 67
</code></pre>

<p>if you only want to modify the list of inputs:</p>

<pre><code>l = ['A10', 'A2']
l = [ re.sub(r'([A-Z]) *(\d+)', r'\1 \2', x) for x in l]
print l
</code></pre>

<p>this prints:</p>

<pre><code>['A 10', 'A 2']
</code></pre>

python split alphanumeric