[python] Lift is short, I need python!
2015-07-26 00:27
591 查看
Example 1: Reverse words in a String
Given an input string, reverse the string word by word.
For example,
Given s = "
return "
Given an input string, reverse the string word by word.
For example,
Given s = "
the sky is blue",
return "
blue is sky the".
class Solution: # @param s, a string # @return a string def reverseWords(self, s): if len(s)==0 : return s #reverse the whole string first s=s[::-1] sret="" wordlist=s.split(' ') for word in wordlist: if sret!="" and word!="": sret+=" " word=word[::-1] if word!="": sret+=word return sret
相关文章推荐
- Python实现截屏的函数
- python发邮件
- Python GUI漫谈
- python链接数据库
- python生成一个字典的嵌套
- python中的参数传递
- Python图形GUI工具包tkinter如何调整元件在窗口中的位置几何布局管理
- Python GUI编程 1.5 细数一些常用的窗口设置
- python MySQLdb 常用实例
- Python - 两个列表(list)组成字典(dict)
- Python - 字典(dict)删除元素
- Python - 字典按值(value)排序
- python时间模块介绍
- Python函数式编程指南(二):函数
- python 把自定义的函数添加到python库中的方法
- Python函数式编程指南(一):概述
- python : 随机数
- python递归创建目录
- Python项目8:使用XML-RPC进行文件共享
- python下PCA算法与人脸识别