基于python3实现倒叙字符串
这篇文章主要介绍了基于python3实现倒叙字符串,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
google测试工程师的一道题:
设计一个函数,使用任意语言,完成以下功能:
一个句子,将句子中的单词全部倒排过来,但单词的字母顺序不变。比如,Thisisarealworld,输出结果为
worldrealaisthis.
下面利用python来实现:
句子为:
代码如下
#!/usr/bin/envpython3.4 #-*-coding:utf-8-*- #某一段文字 data="Youdon'tneedustotellyouthatChina'sInternetspaceisbooming.Withtheworld'slargestInternetuserpopulation—686millionasofJanuary2016—andalongwaytogotoreachInternetpenetrationlevelsofdevelopedcountries,China'sInternetindustryisgrowinginbothscaleandinfluence.AndasmoreandmoreChineseuserscomeonline,Baiducontinuestoinnovatetomeettheirchangingneedsanddiversetastes.Weaimtoservetheneedsofourusersandcustomerswithproductsandsolutionsthatprioritizetheuserexperienceandreflectourcorporateculture–simpleandreliable." #按照空格分割 strings=data.split() arr=[] #打印出来 forstringinstrings: arr.append(string) #将文本倒叙 arr.reverse() #按照空格将文本变为字符串 newstring="".join(arr) print(newstring)
结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短