+ 1
Is there anyone who solved "No Numerals" problem from SoloLearn's code coach with Python ?
I just solved this problem but something's goes wrong and I can't figure it out. There is 6 test case and and I passed four. Test case #4 and #5 shows wrong but I can't see them for the apps policy. Here is my code and thankyou very much for helping me... text= input().lower() text=text.split() lst=['zero','one','two', 'three','four', 'five', 'six', 'seven', 'eight', 'nine','ten'] dic={} for num,val in enumerate(lst): dic[val]=str(num) dic= {value: i for i, value in dic.items()} d=[] for word in text: if word in dic: d.append(dic[word]) else: d.append(word) join= ' '.join(d) print(join) Btw,. This is the problem link... https://www.sololearn.com/coach/64?ref=app
6 odpowiedzi
+ 1
https://code.sololearn.com/cPnJxYFky5cV/?ref=app
This is mine, but I'll also check yours
+ 1
wow 😍 , your code is much more easier and perfect, thankyou bro. 💕 Can you suggest me , what's wrong with mine?
+ 1
Yours works fine,
With spaces between the inputs
+ 1
I don't see a problem with the code, but the test cases...
0
Thank you bro, should I change anything ?
0
Btw, First I apply this... But there is no module called ' num2words ' in SoloLearn. But this is a awesome module, you convert any number with this. You just have change the range...
from num2words import num2words
text= input().lower()
text=text.split()
lst=[]
dic={}
for i in range (10):
x=num2words(i)
lst.append(x)
for num,val in enumerate(lst):
dic[val]=str(num)
dic= {value: i for i, value in dic.items()}
d=[]
for word in text:
if word in dic:
d.append(dic[word])
else:
d.append(word)
join= ' '.join(d)
print(join)