Python 单词字母顺序不变且所有倒排
翻出google測试project师的一道题目:
设计一个函数,不论什么语言都能够,实现下面功能:
一个句子,将句子中的单词所有倒排过来,但单词的字母顺序不变。eg. this is a real world输出结果为:world real a is this
笔者用Python实现例如以下:
#! /usr/bin/env python
# -* -coding:utf-8-*-
def str_reverse(str):
returnstr_dst
if __name__ == ‘__main__’:
forstr_out in str_reverse(raw_input(‘plz input ur sentence:’)):
printstr_out,
Python is Python!
[A1]以空格为分隔符,将单词取出放入list中。
关于split():
string.split(s[, sep[, maxsplit]])
Return a list of the words of thestring s. If the optional second argument sep is absent or None, the words areseparated by arbitrary strings of whitespace characters (space, tab, newline,return, formfeed). If the second argument sep is present and not None,
itspecifies a string to be used as the word separator. The returned list willthen have one more item than the number of non-overlapping occurrences of theseparator in the string. If maxsplit is given, at most maxsplit number ofsplits occur, and the remainder
of the string is returned as the final elementof the list (thus, the list will have at most maxsplit+1 elements). If maxsplitis not specified or -1, then there is no limit on the number of splits (allpossible splits are made).
The behavior of split on an emptystring depends on the value of sep. If sep is not specified, or specified asNone, the result will be an empty list. If sep is specified as any string, theresult will be a list containing one element which is an empty string
[A2]反转list
关于reverse():
s.reverse() reverses the items of s inplace
The reverse() methods modify the listin place for economy of space when reversing a large list. To remind you thatthey operate by side effect, they don’t return the reversed list.
Python 单词字母顺序不变且所有倒排的更多相关文章
- OJ_单词倒排
题目描述:对字符串中的所有单词进行倒排. 说明: 1.每个单词是以26个大写或小写英文字母构成,可以用一个“-”中连接线连接单词两部分表示一个单词,但是仅限一个“-”,出现两个“--”则为非构成单词的 ...
- 35:字符串单词倒排 ReverseWords
题目描述:对字符串中的所有单词进行倒排. 说明: 1.每个单词是以26个大写或小写英文字母构成: 2.非构成单词的字符均视为单词间隔符: 3.要求倒排后的单词间隔符以一个空格表示:如果原字符串中相邻单 ...
- OpenJudge计算概论-单词倒排【把句子内单词的顺序翻转】
/*================================================== 单词倒排 总时间限制: 1000ms 内存限制: 65536kB 描述 编写程序,读入一段英文 ...
- AC日记——单词倒排 1.7 28
28:单词倒排 总时间限制: 1000ms 内存限制: 65536kB 描述 编写程序,读入一行英文(只包含字母和空格,单词间以单个空格分隔),将所有单词的顺序倒排并输出,依然以单个空格分隔. 输 ...
- Openjudge-计算概论(A)-单词倒排
描述: 编写程序,读入一行英文(只包含字母和空格,单词间以单个空格分隔),将所有单词的顺序倒排并输出,依然以单个空格分隔. 输入输入为一个字符串(字符串长度至多为100).输出输出为按要求排续后的字符 ...
- python获取字母在字母表对应位置的几种方法及性能对比较
python获取字母在字母表对应位置的几种方法及性能对比较 某些情况下要求我们查出字母在字母表中的顺序,A = 1,B = 2 , C = 3, 以此类推,比如这道题目 https://project ...
- IT公司100题-10-翻转句子中单词的顺序
问题描述: 输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变. 句子中单词以空格符隔开.为简单起见,标点符号和普通字母一样处理. 例如输入“Hello world!”,则输出“world ...
- 翻转句子中单词的顺序 C语言
输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变.句子中单词以空格符隔开. 为简单起见,标点符号和普通字母一样处理. 比如将"I am a student"转化为&q ...
- H面试程序(4):翻转句子中单词的顺序 .
题目:输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变. 句子中单词以空格符隔开.为简单起见,标点符号和普通字母一样处理. 例如输入“I am a student.”,则输出“stude ...
随机推荐
- poj 1088 滑雪问题
滑雪问题 import java.util.Scanner; public class Main{ static int a[][],r,c; public static void main(Stri ...
- Java之Static静态修饰符详解
Java之Static静态修饰符详解 Java之Static静态修饰符详解 一.特点 1.随着类的加载而加载,随着类的消失而消失,生命周期最长 2.优先于对象存在 3.被所有类的对象共享 4.可以直接 ...
- UVa 10256 The Great Divide,推断两个凸包是否相离
先从给出的两个点集中分别计算出两个凸包, 然后推断两个凸包是否相离. #include<cstdio> #include<vector> #include<cmath&g ...
- vim的正则表达式(二)应用实例
本文出自 http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...
- HLJOJ1015(多源最短路径失真)
意甲冠军:n,m,k,有着n村.有着k路,每个村都有一个电话亭,现在,我们要建立在村中心展台,快递每一个需要同村的中心村,然后返回报告(有向图),有着m电话,假设村配置的手机,那么你并不需要报告.最低 ...
- Ubuntu12.04 Git 服务器详细配置
Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目,学过Linux的都知道,Git的优点我就不再多说了,我也是很喜欢Linux的.今天我们一起学习Git服务器在Ubunt ...
- js获取某个标签中的信息
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- 调起qq临时通话
1.在qq推广的网站上的推广工具中将个人或者公司的qq确认为推广qq 2. 选择好显示的图片,将代码拷贝到页面上就可以了
- [HeadFirst-HTMLCSS学习笔记][第十四章交互活动]
表单 <form action="http://wickedlysmart.com/hfhtmlcss/contest.php" method="POST" ...
- WebApplication和WebSite的区别
不同点 1. 创建方式不同 一个是FILE->NEW->PROJECT->ASP.NET WEB APPLICATION 另外一个是 FILE->NEW->WEBSITE ...