首页 > 其他 > 详细

输入英文,每一句内容翻转. 标点符号(,.?!)位置不动

时间:2020-11-29 10:38:44      阅读:39      评论:0      收藏:0      [点我收藏+]
# # where are you going?I am going home.
# # 输出处理后的文件,文件内容期望是:
# # going you are where?home going am I.
import string

s = "where are you going!I am going home."
start = 0
end = 0
length = len(s)
# s2 = s.split()
# print("s2:",s2)
result = ""

for i in range(len(s)):
    #print(s[i])
    if s[i] in string.punctuation:
        end = i
        result += " ".join(s[start:end].split()[::-1])
        # s[i]标点符号
        result += s[i]
        start = end + 1

if end != length - 1:
    end = length
    result += " ".join(s[start:end].split()[::-1])

print(result)

  going you are where!home going am I.

输入英文,每一句内容翻转. 标点符号(,.?!)位置不动

原文:https://www.cnblogs.com/testerren/p/14054980.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!