如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#!/usr/bin/python # -*- coding: utf-8 -*- def rever(sentence): newwords = [] words = sentence.split() words.reverse() space = ' ' #单词之间一个间隔 for word in words: newword = [] new = '' #单词的字母间无间隔 l = len (word) for i in range (l): newword.append(word[l - i - 1 ]) neww = new.join(newword) newwords.append(neww) print space.join(newwords) rever( 'what\'s your problem man ?' ) |
运行结果:
1
|
? nam melborp ruoy s'tahw |
以上这篇Python给定一个句子倒序输出单词以及字母的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/horseinch/article/details/51850434