import argparse
def parse_range(astr):
result = set()
for part in astr.split(','):
x = part.split('-')
result.update(range(int(x[0]), int(x[-1]) + 1))
return sorted(result)
parser = argparse.ArgumentParser()
parser.add_argument('-n', type=parse_range)
args = parser.parse_args()
print(args.n)
выходы
% script.py -n 3-6
[3, 4, 5, 6]
% script.py -n 3,6
[3, 6]
% script.py -n 22-27,51-64
[22, 23, 24, 25, 26, 27, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64]