+ 3

[solved] is it possible to remove digit from the sentence ??

string = " i am python23 and the98 great0" all_words = string.split() # a = string.replace("2","") # print(a) for word in all_words: for char in word: if char.isdigit(): a = string.replace(f"{char}"," ") print(a) this code is not working !!! desired output : -" i am python and the great"

1st Feb 2021, 1:44 PM
Hemant Kosrekar
Hemant Kosrekar - avatar
3 Antworten
+ 3
Remove the "a=string" and add the following , string=string.replace(f"{char}","") That " a= " stores only the string with last digit removed .
1st Feb 2021, 2:14 PM
Abhay
Abhay - avatar
+ 1
Hey Hemant Kosrekar yes it's true Simply go through each letter of each word in given sentence then eachLetter. isdigit() will help you to figure out its digit or not then you can remove it. Be careful remove doesn't work for strings
1st Feb 2021, 1:49 PM
Mohd Aadil
Mohd Aadil - avatar
0
Thanks Abhay I got the answer !
1st Feb 2021, 2:25 PM
Hemant Kosrekar
Hemant Kosrekar - avatar