Simple case: For a given string input like '1-12A', I'd like to output a list like
['1A', '2A', '3A', ... , '12A']
That's easy enough, I could use something like the following code:
import re
input = '1-12A'
begin = input.split('-')[0] #the first number
end = input.split('-')[-1] #the last number
letter = re.findall(r"([A-Z])", input)[0] #the letter
[str(x)+letter for x in range(begin, end+1)] #works only if letter is behind number
But sometimes I'll have cases where the input is like 'B01-B12', and I'd like the output to be like this:
['B01', 'B02', 'B03', ... , 'B12']
Now the challenge is, what's the most pythonic way to create a function to can build up such lists from either of the above two inputs? It might be a function that accepts the begin, end and letter inputs, but it has to account for leading zeros, and the fact that the letter could be in front or behind the number.