I have strings that contain a number somewhere in them and I'm trying to replace this number with their word notation (ie. 3 -> three). I have a function that does this. The problem now is finding the number inside the string, while keeping the rest of the string intact. For this, I opted to use the re.sub
function, which can accept a "callable". However, the object passed to it is the internal _sre.SRE_Match
and I'm not sure how to handle it. My function accepts a number or its string representation.
How should I write some helper function which can be used to bridge the re.sub
call with my function doing the required processing? Alternatively, is there a better way to do what I want?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…