基于python3实现倒叙字符串


Posted in Python onFebruary 18, 2020

这篇文章主要介绍了基于python3实现倒叙字符串,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

google测试工程师的一道题:

设计一个函数,使用任意语言,完成以下功能:

一个句子,将句子中的单词全部倒排过来,但单词的字母顺序不变。比如,This is a real world,输出结果为

world real a is this.

下面利用python来实现:

句子为:

基于python3实现倒叙字符串

代码如下

#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

#某一段文字
data = "You don't need us to tell you that China's Internet space is booming. With the world's largest Internet user population—686 million as of January 2016—and a long way to go to reach Internet penetration levels of developed countries, China's Internet industry is growing in both scale and influence. And as more and more Chinese users come online, Baidu continues to innovate to meet their changing needs and diverse tastes. We aim to serve the needs of our users and customers with products and solutions that prioritize the user experience and reflect our corporate culture ? simple and reliable."

#按照空格分割
strings = data.split()
arr = []

#打印出来
for string in strings:
  arr.append(string)

#将文本倒叙
arr.reverse()
# 按照空格将文本变为字符串
newstring = " ".join(arr)

print(newstring)

结果:

基于python3实现倒叙字符串

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
浅谈python中scipy.misc.logsumexp函数的运用场景
Jun 23 Python
Python编码类型转换方法详解
Jul 01 Python
Python编程判断这天是这一年第几天的方法示例
Apr 18 Python
详解Python3操作Mongodb简明易懂教程
May 25 Python
python爬虫之BeautifulSoup 使用select方法详解
Oct 23 Python
python邮件发送smtplib使用详解
Jun 16 Python
flask中过滤器的使用详解
Aug 01 Python
pycham查看程序执行的时间方法
Nov 29 Python
Python按照list dict key进行排序过程解析
Apr 04 Python
python根据用户需求输入想爬取的内容及页数爬取图片方法详解
Aug 03 Python
浅析Python 中的 WSGI 接口和 WSGI 服务的运行
Dec 09 Python
一劳永逸彻底解决pip install慢的办法
May 24 Python
Python日期格式和字符串格式相互转换的方法
Feb 18 #Python
Python数组并集交集补集代码实例
Feb 18 #Python
通过python检测字符串的字母
Feb 18 #Python
Python安装whl文件过程图解
Feb 18 #Python
python下载卫星云图合成gif的方法示例
Feb 18 #Python
如何使用python传入不确定个数参数
Feb 18 #Python
scrapy数据存储在mysql数据库的两种方式(同步和异步)
Feb 18 #Python
You might like
PHP中预定义的6种接口介绍
2015/05/12 PHP
Thinkphp5框架简单实现钩子(Hook)行为的方法示例
2019/09/03 PHP
基于JQuery实现的图片自动进行缩放和裁剪处理
2014/01/31 Javascript
javaScript中的原型解析【推荐】
2016/05/05 Javascript
JavaScript实现瀑布流以及加载效果
2017/02/11 Javascript
js实现图片加载淡入淡出效果
2017/04/07 Javascript
layui文件上传实现代码
2017/05/20 Javascript
jQuery表单验证之密码确认
2017/05/22 jQuery
微信小程序 空白页重定向解决办法
2017/06/27 Javascript
javascript基本常用排序算法解析
2017/09/27 Javascript
vue实现动态按钮功能
2019/05/13 Javascript
[01:30]DOTA2上海特锦赛现场采访 Loda倾情献唱
2016/03/25 DOTA
[01:10]DOTA2 Supermajor:英雄,由我们见证
2018/05/14 DOTA
[36:05]完美世界DOTA2联赛循环赛 Forest vs DM 第一场 11.06
2020/11/06 DOTA
python模拟登录百度代码分享(获取百度贴吧等级)
2013/12/27 Python
Python实例之wxpython中Frame使用方法
2014/06/09 Python
python中将字典转换成其json字符串
2014/07/16 Python
Python上传package到Pypi(代码简单)
2016/02/06 Python
pandas实现选取特定索引的行
2018/04/20 Python
Python常用字符串替换函数strip、replace及sub用法示例
2018/05/21 Python
Python中的CSV文件使用"with"语句的方式详解
2018/10/16 Python
python3 小数位的四舍五入(用两种方法解决round 遇5不进)
2019/04/11 Python
python多进程间通信代码实例
2019/09/30 Python
python实现发送QQ邮件(可加附件)
2020/12/23 Python
Pycharm 跳转回之前所在页面的操作
2021/02/05 Python
对CSS3选择器的研究(详解)
2016/09/16 HTML / CSS
css3 自定义字体font-face使用介绍
2014/05/14 HTML / CSS
中国最大的名表商城:万表网
2016/08/29 全球购物
马来西亚在线时尚女装商店:KEI MAG
2017/09/28 全球购物
流行文化收藏品:Sideshow(DC漫画,星球大战,漫威)
2019/03/17 全球购物
材料成型专业个人求职信范文
2013/09/25 职场文书
2014年关于两会精神的心得体会
2014/03/17 职场文书
退休教师欢送会主持词
2014/03/31 职场文书
2015年师德师风自我评价范文
2015/03/05 职场文书
python爬不同图片分别保存在不同文件夹中的实现
2021/04/02 Python
使用Python脚本对GiteePages进行一键部署的使用说明
2021/05/27 Python