python - Split string by hyphen -
i have strings in format of feet'-inches" (i.e. 18'-6") , want split values of feet , inches separated.
i have tried:
re.split(r'\s|-', `18'-6`) but still returns 18'-6.
desired output: [18,6] or similar
thanks!
just split replacing ':
s="18'-6" a, b = s.replace("'","").split("-") print(a,b) if have both " , ' 1 must escaped split , slice second last character:
s = "18'-6\"" a, b = s.split("-") print(a[:-1], b[:-1]) 18 6
Comments
Post a Comment