题解 | #单词倒排#
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
for i in range(len(s)):#将所有非字母字符替换为空格
if not s[i].isalpha():#注意字符串自带函数用法,否则较难实现
s = s.replace(s[i],' ')
s = s.split(' ')
s = s[::-1]
print(' '.join(s))
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
for i in range(len(s)):#将所有非字母字符替换为空格
if not s[i].isalpha():#注意字符串自带函数用法,否则较难实现
s = s.replace(s[i],' ')
s = s.split(' ')
s = s[::-1]
print(' '.join(s))
相关推荐