+ 1
Help needed.. How to remove punctuation from words?
Average word length code https://code.sololearn.com/cyzp2TREdYGd/?ref=app https://code.sololearn.com/cyzp2TREdYGd/?ref=app
6 Respostas
+ 1
from string import punctuation
myinput = input()
for x in punctuation: # or use something like..for x in "?#~[]*&^%$£()\"\'!":
myinput = myinput.replace(x, '')
+ 6
Omar Jafar, thanks! I used a list comprehension, to create a new list, except using punctuation. The print statement puts all calculation together in one line. This can also be done in multiple steps.
+ 4
This is a sample done in the sense of 'pythonic way':
from math import ceil
from string import punctuation
ess = input().split()
ess1 = [i for i in ' '.join(ess) if i not in punctuation]
print(ceil((sum([len(i) for i in ess1])) / len(ess)))
+ 2
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥
Lothar
I tried your codes too, interesting logic.
+ 1
How about string methods eg. isalpha(),isalmum() etc.?
input_string = input()
c=0
k=len(n.split())
for i in input_string:
if(i.isalpha()):
c=c+1
then you do your division and round from there.
+ 1
Thanx you guys it worked.
Used a for lor loop to replace punctuations in input string with white space
So the split() returns a list of words only (without punctuations)