current position:Home>Program supplementary question: input an English sentence and output the number of letters of each word

Program supplementary question: input an English sentence and output the number of letters of each word

2022-01-26 22:47:17 CSDN Q & A

for example :
Input :Hello Python world!
Output :5 6 5

import stringwords = input()#  Remove all punctuation marks ....#  English sentence segmentation ________f = lambda x: len(x)for i in __________: print(f(i),_______)

Request to supplement the ellipsis at the fourth line and the code at the horizontal line




Refer to the answer 1:
import stringwords = input()#  Remove all punctuation marks import repunctuation = '!,;:?"\'、,;'words = re.sub(r'[{}]+'.format(punctuation),' ',words).strip()#  English sentence segmentation lst = words.split()f = lambda x: len(x)for i in lst:    print(f(i), end=' ')



Refer to the answer 2:



Refer to the answer 3:
import stringwords = input()#  Remove all punctuation marks punct = str.maketrans({key: "" for key in string.punctuation})string_c = words.translate(punct)#  English sentence segmentation l = []for i in string_c.split(' '):    l.append(i)f = lambda x: len(x)for i in l:    print(f(i), end=' ')



Refer to the answer 4:



Refer to the answer 5:
import stringwords = input()# ....#  English sentence segmentation lst = words.replace('!', '').split()f = lambda x: len(x)for i in lst:    print(f(i), end=' ')



Refer to the answer 6:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262247159713.html

Random recommended