The wonders of Python!!
Hi guys, this code converts the numbers inside the text to words, but a problem occurs with number 10 at the end of the string! This is more interesting that if we change the first number of the string (1), to 10, the problem will be solved! Can someone explain that?! import re str1 = "1 plus 2 plus 3 p 4 p 5 p 6 p 7 p 8 p 9 p 10" nums = {"1": "one", "2": "two", "3": "three", "4": "four", "5": " five", "6": "six", "7": "seven", "8": "eight", "9": "nine", "10": "ten"} d = re.findall('\d+', str1 ) t = tuple(d) def rep(x, t): l = len(t) i = 0 for i in range(0, l + 2): if i == l: return x elif i < l: if t[i] in x: x = x.replace(t[i], nums[t[i]]) i += 1 print(rep(str1, t))