Problem:
I have a list of strings and I need to get rid of whitespaces before and after substring that looks like 'digit / digit'. Been stuck on this for quite a while and still don't understand how to fix itI will appreciate any help.
Sample input:
steps = [
'mix butter , flour , 1 / 3 c',
'sugar and 1-1 / 4 t',
'vanilla'
]
Expected output:
[
'mixbutter,flour,1 / 3c',
'sugarand1-1 / 4t',
'vanilla'
]
My approach:
steps_new = []
for step in steps:
step = re.sub(r'\s+[^\d+\s/\s\d+]','',step)
steps_new.append(step)
steps_new
My output:
[
'mixutterlour 1 / 3',
'sugarnd 1-1 / 4',
'vanilla'
]