基于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判断端口是否打开的实现代码
Feb 10 Python
python3模拟百度登录并实现百度贴吧签到示例分享(百度贴吧自动签到)
Feb 24 Python
关于反爬虫的一些简单总结
Dec 13 Python
Python numpy 提取矩阵的某一行或某一列的实例
Apr 03 Python
Python实现数据结构线性链表(单链表)算法示例
May 04 Python
eclipse创建python项目步骤详解
May 10 Python
django 实现手动存储文件到model的FileField
Mar 30 Python
Python3 pywin32模块安装的详细步骤
May 26 Python
Pandas中DataFrame基本函数整理(小结)
Jul 20 Python
python如何获得list或numpy数组中最大元素对应的索引
Nov 16 Python
python爬虫框架feapde的使用简介
Apr 20 Python
详解Python中的for循环
Apr 30 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程序的方法
2009/03/09 PHP
PHP8.0新功能之Match表达式的使用
2020/07/19 PHP
ImageFlow可鼠标控制图片滚动
2008/01/30 Javascript
js tab效果的实现代码
2009/12/26 Javascript
在js文件中如何获取basePath处理js路径问题
2013/07/10 Javascript
js将当前时间格式转换成时间搓(自写)
2013/09/26 Javascript
js算法中的排序、数组去重详细概述
2013/10/14 Javascript
js ajaxfileupload.js上传报错的解决方法
2016/05/05 Javascript
jQuery插件WebUploader实现文件上传
2016/11/07 Javascript
bootstrap日历插件datetimepicker使用方法
2016/12/14 Javascript
JQuery validate 验证一个单独的表单元素实例
2017/02/17 Javascript
详解Vue2.0里过滤器容易踩到的坑
2017/06/01 Javascript
JS实现移动端整屏滑动的实例代码
2017/11/10 Javascript
NodeJS父进程与子进程资源共享原理与实现方法
2018/03/16 NodeJs
微信小程序methods中定义的方法互相调用的实例代码
2018/08/07 Javascript
从源码里了解vue中的nextTick的使用
2018/11/22 Javascript
layui radio单选限制下一个radio单选的实例
2019/09/03 Javascript
js实现3D旋转效果
2020/08/18 Javascript
解决antd datepicker 获取时间默认少8个小时的问题
2020/10/29 Javascript
[12:21]VICI vs TNC (BO3)
2018/06/07 DOTA
[34:41]夜魇凡尔赛茶话会 第二期02:你画我猜
2021/03/11 DOTA
Python绑定方法与非绑定方法详解
2017/08/18 Python
python中获得当前目录和上级目录的实现方法
2017/10/12 Python
对Python3中的input函数详解
2018/04/22 Python
pygame实现俄罗斯方块游戏(AI篇1)
2019/10/29 Python
Python连接字符串过程详解
2020/01/06 Python
如何在mac版pycharm选择python版本
2020/07/21 Python
Python爬虫如何破解JS加密的Cookie
2020/11/19 Python
python 爬虫网页登陆的简单实现
2020/11/30 Python
Python3+Flask安装使用教程详解
2021/02/16 Python
英国最大的独立玩具专卖店:The Entertainer
2019/09/06 全球购物
药品质量检测应届生求职信
2013/11/14 职场文书
2014社区三八妇女节活动总结
2014/03/01 职场文书
社区学习雷锋活动总结
2014/04/25 职场文书
党的群众路线教育实践活动剖析材料
2014/09/30 职场文书
zabbix如何添加监控主机和自定义监控项
2022/08/14 Servers