翻出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):

str_dst =str.split()[A1]

str_dst.reverse()[A2]

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 单词字母顺序不变且所有倒排的更多相关文章

  1. OJ_单词倒排

    题目描述:对字符串中的所有单词进行倒排. 说明: 1.每个单词是以26个大写或小写英文字母构成,可以用一个“-”中连接线连接单词两部分表示一个单词,但是仅限一个“-”,出现两个“--”则为非构成单词的 ...

  2. 35:字符串单词倒排 ReverseWords

    题目描述:对字符串中的所有单词进行倒排. 说明: 1.每个单词是以26个大写或小写英文字母构成: 2.非构成单词的字符均视为单词间隔符: 3.要求倒排后的单词间隔符以一个空格表示:如果原字符串中相邻单 ...

  3. OpenJudge计算概论-单词倒排【把句子内单词的顺序翻转】

    /*================================================== 单词倒排 总时间限制: 1000ms 内存限制: 65536kB 描述 编写程序,读入一段英文 ...

  4. AC日记——单词倒排 1.7 28

    28:单词倒排 总时间限制:  1000ms 内存限制:  65536kB 描述 编写程序,读入一行英文(只包含字母和空格,单词间以单个空格分隔),将所有单词的顺序倒排并输出,依然以单个空格分隔. 输 ...

  5. Openjudge-计算概论(A)-单词倒排

    描述: 编写程序,读入一行英文(只包含字母和空格,单词间以单个空格分隔),将所有单词的顺序倒排并输出,依然以单个空格分隔. 输入输入为一个字符串(字符串长度至多为100).输出输出为按要求排续后的字符 ...

  6. python获取字母在字母表对应位置的几种方法及性能对比较

    python获取字母在字母表对应位置的几种方法及性能对比较 某些情况下要求我们查出字母在字母表中的顺序,A = 1,B = 2 , C = 3, 以此类推,比如这道题目 https://project ...

  7. IT公司100题-10-翻转句子中单词的顺序

    问题描述: 输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变. 句子中单词以空格符隔开.为简单起见,标点符号和普通字母一样处理. 例如输入“Hello world!”,则输出“world ...

  8. 翻转句子中单词的顺序 C语言

    输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变.句子中单词以空格符隔开. 为简单起见,标点符号和普通字母一样处理. 比如将"I am a student"转化为&q ...

  9. H面试程序(4):翻转句子中单词的顺序 .

    题目:输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变. 句子中单词以空格符隔开.为简单起见,标点符号和普通字母一样处理. 例如输入“I am a student.”,则输出“stude ...

随机推荐

  1. IOS开发之语音合成(科大讯飞)详解

    1.注册讯飞账号,申请APPID(注意选择IOS平台) 2.加载所需要的类库 3.导入所需要的类库文件头 4.调用申请的APPID以及所需函数,完成语音合成(需要参考官方给出的SDK文件)   详细步 ...

  2. LabView 下载与安装

    labview2014是目前labview软件的最新版本,新版本增加了多个VI服务器对象,增加了多个vi脚本对象,增加了labview第三方许可和激活工具包,同时针对程序框图.编辑环境.应用程序生成器 ...

  3. Tcp 数据对象传输接口对象设计

    输入是一个对象inputObj,接口对象.Send(inputObj),对端接收之后解包成outputObj(与inputObj应相同),触发onPackageReceive事件 事件 public ...

  4. Chrome开发者工具详解 (5):Application、Security、Audits面板

    Application面板简介 该面板主要是记录网站加载的所有资源信息,包括存储数据(Local Storage.Session Storage.IndexedDB.Web SQL.Cookies). ...

  5. Toolbar 和 CollapsingToolbarLayout一起使用时menu item无点击反应解决办法

    昨天一直在琢磨为什么Toolbar和CollapsingToolbarLayout一起使用时menu item无点击放应的原因,后来在stackoverflow上一条回答,说可能是Toolbar的背景 ...

  6. 原创+部分引用啦:C# Winform界面中的分隔线问题

    C sharp 中Winform中的控件很多,一个小小的问题居然会绕上一个小弯子,做界面的时候, 你需要在界面上弄一条分隔线,把相关的功能分隔开来,结果原来在其它 IDE编辑器里很容易实现的这个功能, ...

  7. 安装SQL2008时遇到"未能加载文件或"file:///d:microsoft..sql.chainer.packagedata.dll"或它的某个依赖项

    安装SQL2008时遇到"未能加载文件或"file:///d:microsoft..sql.chainer.packagedata.dll"或它的某个依赖项,如下图所示 ...

  8. windows在文件夹快速打开命令行

    普通打开方式 按住shift键,在指定的文件夹上右键,会发现有"在此处打开命令行窗口"的字样,选择该项,即可打开命令行,并且路径刚好是你刚才选择的文件夹路径 管理员方式打开 修改注 ...

  9. [Leetcode] Longest Substring Without Repeating Characters (C++)

    题目: Given a string, find the length of the longest substring without repeating characters. For examp ...

  10. Zend Studio 文件头和方法注释设置

    在zend studio中选择窗口->首选项->PHP–>编辑器 –>模板 –>新建 然后添加 funinfo或fileinfo 模板代码根据下边定义的COPY过去就可以 ...