I can't wrap my head around this, I need to re.sub multiple times looking for different patterns. The below script works but it's definitely not pythonic.
I thought I could use a dictionary where the first number is the key, and value would be what it gets replaced by.
lines contains rows of data like "abc/3/def/ghi/jkl/mno//.
Any pointers in how I can clean this code?
I'm after an output that replaces the nominal 3 in the above example to Size-3.
for line in lines:
tokens = line.split(delimiter)
tokens = [re.sub('^4$', 'Size-4', token) for token in tokens]
tokens = [re.sub('^5$', 'Size-5', token) for token in tokens]
tokens = [re.sub('^6$', 'Size-6', token) for token in tokens]
tokens = [re.sub('^7$', 'Size-7', token) for token in tokens]
tokens = [re.sub('^8$', 'Size-8', token) for token in tokens]
tokens = [re.sub('^9$', 'Size-9', token) for token in tokens]
tokens = [re.sub('^10$', 'Size-10', token) for token in tokens]
tokens = [re.sub('^12$', 'Size-12', token) for token in tokens]
tokens = [re.sub('^14$', 'Size-14', token) for token in tokens]
tokens = [re.sub('^16$', 'Size-16', token) for token in tokens]
print(tokens)