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>A regex would be a good approach for this, you're looking for a letter <code>([A-Z])</code> followed by an optional space <code>?</code> followed by one or more digits <code>(\d+)</code>:</p>

<pre><code>&gt;&gt;&gt; import re
&gt;&gt;&gt; re.match('([A-Z]) ?(\d+)', 'A10').groups()
('A', '10')
&gt;&gt;&gt; re.match('([A-Z]) ?(\d+)', 'A 10').groups()
('A', '10')
</code></pre>

python split alphanumeric