中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Python 單詞字母順序不變且全部倒排

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用

設(shè)計(jì)一個(gè)函數(shù),任何語(yǔ)言都可以,實(shí)現(xiàn)以下功能:

一個(gè)句子,將句子中的單詞全部倒排過(guò)來(lái),但單詞的字母順序不變。eg.  this is a real world輸出結(jié)果為:world real a is this

 

筆者用Python實(shí)現(xiàn)如下:

 

#! /usr/bin/env python

# -* -coding:utf-8-*-

 

def str_reverse(str):

         str_dst =str.split()[A1] 

         str_dst.reverse()[A2] 

         return str_dst

 

if __name__ == ‘__main__’:

         for str_out in str_reverse(raw_input(‘plz input ur sentence:’)):

                   print str_out,

Python is Python!


 [A1]以空格為分隔符,將單詞取出放入list中。

關(guān)于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

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:自己封裝的Java excel數(shù)據(jù)讀取方法

下一篇:Hibernate 泛型DAO實(shí)現(xiàn)代碼