Python给定一个句子倒序输出单词以及字母的方法

yipeiwu_com6年前Python基础

如下所示:

#!/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 ?')

运行结果:

? nam melborp ruoy s'tahw

以上这篇Python给定一个句子倒序输出单词以及字母的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

使用Python对Access读写操作

学习Python的过程中,我们会遇到Access的读写问题,这时我们可以利用win32.client模块的COM组件访问功能,通过ADODB操作Access的文件。 需要下载安装pywi...

Python中使用md5sum检查目录中相同文件代码分享

复制代码 代码如下: """This module contains code from Think Python by Allen B. Downey http://thinkpyth...

深入了解Python在HDA中的应用

深入了解Python在HDA中的应用

Event Handler 在HDA中,要创建Python脚本,需要先选择一个事件处理器(EventHandle),他表示你要在什么时候执行你现在所创建的脚本命令 On Created...

Python、 Pycharm、Django安装详细教程(图文)

Python、 Pycharm、Django安装详细教程(图文)

最近做项目要用到python,那么不用说就得先配置好python环境 以及选择好python工具。接下来分享自己的安装过程。 (一)、Python的安装 1.先进入官网下载python版...

Python实现对百度云的文件上传(实例讲解)

Python实现对百度云的文件上传(实例讲解)

环境准备 python3.6 PyCharm 2017.1.3 Windows环境 框架搭建 selenium3.6 安装方法: pip install selenium 实现步骤: 一...