基于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中os操作文件及文件路径实例汇总
Jan 15 Python
python实现模拟按键,自动翻页看u17漫画
Mar 17 Python
详解常用查找数据结构及算法(Python实现)
Dec 09 Python
详解python eval函数的妙用
Nov 16 Python
Python如何发布程序的详细教程
Oct 09 Python
基于Python实现用户管理系统
Feb 26 Python
Python使用pyautocad+openpyxl处理cad文件示例
Jul 11 Python
关于Python3 类方法、静态方法新解
Aug 30 Python
jupyter lab文件导出/下载方式
Apr 22 Python
python多线程实现同时执行两个while循环的操作
May 02 Python
Python Selenium自动化获取页面信息的方法
Aug 31 Python
基于python的matplotlib制作双Y轴图
Apr 20 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
数据库的日期格式转换
2006/10/09 PHP
php二维数组排序与默认自然排序的方法介绍
2013/04/27 PHP
php计算多维数组中所有值总和的方法
2015/06/24 PHP
Yii基于CActiveForm的Ajax数据验证用法示例
2016/07/14 PHP
PHP面向对象五大原则之里氏替换原则(LSP)详解
2018/04/08 PHP
js验证表单大全
2006/11/25 Javascript
javascript 选择文件夹对话框(web)
2009/07/07 Javascript
鼠标右击事件代码(asp.net后台)
2011/01/27 Javascript
js实现网站首页图片滚动显示
2013/02/04 Javascript
JS判断数组中是否有重复值得三种实用方法
2013/08/16 Javascript
Javascript写入txt和读取txt文件示例
2014/02/12 Javascript
yepnope.js使用详解及示例分享
2014/06/23 Javascript
用canvas 实现个图片三角化(LOW POLY)效果
2016/02/18 Javascript
jQuery简单实现title提示效果示例
2016/08/01 Javascript
js实现前端分页页码管理
2017/01/06 Javascript
关于Vue.nextTick()的正确使用方法浅析
2017/08/25 Javascript
ES6中Array.find()和findIndex()函数的用法详解
2017/09/16 Javascript
node.js环境搭建图文详解
2018/09/19 Javascript
vue实现下拉菜单树
2020/10/22 Javascript
python正则表达式re模块详细介绍
2014/05/29 Python
Python 字典dict使用介绍
2014/11/30 Python
Python使用cookielib模块操作cookie的实例教程
2016/07/12 Python
详解MySQL数据类型int(M)中M的含义
2016/11/20 Python
Python探索之自定义实现线程池
2017/10/27 Python
在python 不同时区之间的差值与转换方法
2019/01/14 Python
python-Web-flask-视图内容和模板知识点西宁街
2019/08/23 Python
在Sublime Editor中配置Python环境的详细教程
2020/05/03 Python
python如何求100以内的素数
2020/05/27 Python
css3中仿放大镜效果的几种方式原理解析
2020/12/03 HTML / CSS
银行会计财务工作个人的自我评价
2013/10/29 职场文书
2014年新生军训方案
2014/05/01 职场文书
雏鹰争章活动总结
2014/05/09 职场文书
2019最新版股权转让及委托持股协议书范本
2019/08/07 职场文书
85句关于理想的名言警句大全
2019/08/22 职场文书
weblogic服务建立数据源连接测试更新mysql驱动包的问题及解决方法
2022/01/22 MySQL
python中出现invalid syntax报错的几种原因分析
2022/02/12 Python