I want to have yourfeedback. I need to process an input which is a range defined as string:
targets = 'machine[7:10]'
The result that I need is:
results = ['machine07', 'machine08', 'machine09', 'machine10']
Here is what I have coded in Python:
for target in targets:
m = re.search('\\d+:\d+\]', target)
if m:
name = target.split('[')[0]
target_range = re.findall('[0-9]+', target)
print(target_range)
target_range = [int(i) for i in target_range]
for tgt in range(target_range[0],target_range[1]+1):
results.append(name + str(format(tgt, '02d')))
Please, can you tell me is there is a more elegant way or pythonic way of doing the same thing ? ... with NO import module! Thank you.
rean imported module?