I want to use make replacements on a text file which is
one two three pthree two ptwo one two ...(1000+ words)
such that output looks like 1 2 3 p3 2 p2 1 2 ....
My code looks like
dict = { 'zero':'0','one':'1','two':'2','three':'3','four':'4','five':'5','six':'6','seven':'7'}
x = 'one two three pthree two ptwo one two' #reading input from file
for k, v in dict.items():
x = x.replace(k, v)
I have tried these solutions str.replace and regex but both methods give me the same error which is
TypeError: replace() argument 2 must be str, not int
What does this error mean? And how should I resolve it? Thank You
TypeError: replace() argument 2 must be str, not intWell this error just tells you that you need to put in astrtype but you are giving itint. Try first converting it tostrusingstr()function. Probably you're not just providing much details on your question.'phone'will be'ph1', which you might not be anticipating.