Working on my final project and I'm stuck trying to edit user input. The below code should take the first string in a list and check if it's numeric. If it is, great, that's what I want, otherwise, I need to find out where the non-numeric characters are and insert a space between the numbers and the letters, e.g. '110g' -> '110' 'g'
if not item[0].isnumeric():
count = 0
for c in item[0]:
if c == r'[0-9\.]':
print(c)
count += 1
continue
else:
measure = insert_str(item[0], " ", count)
print(measure)
measureList = []
measureList = measure.split(" ")
print(measureList)
item[0] = measureList[0]
item.insert(1, measureList[1])
break
I've run the debugger a few times and it seems that my second if statement if c == r'[0-9\.]':
isn't catching anything, but I can't figure out why. It could be that my regex is completely wrong but from what I've read, I think I'm doing it right.
Any ideas anyone?