基于python3实现倒叙字符串
作者:yaominghui 时间:2023-02-02 17:41:28
这篇文章主要介绍了基于python3实现倒叙字符串,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
google测试工程师的一道题:
设计一个函数,使用任意语言,完成以下功能:
一个句子,将句子中的单词全部倒排过来,但单词的字母顺序不变。比如,This is a real world,输出结果为
world real a is this.
下面利用python来实现:
句子为:
代码如下
#!/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)
结果:
来源:https://www.cnblogs.com/TTyb/p/5903216.html
标签:python,倒叙,字符串


猜你喜欢
Django 删除upload_to文件的步骤
2022-03-23 05:47:14

如何使用微信公众平台开发模式实现多客服
2023-11-14 17:48:37
Python:__eq__和__str__函数的使用示例
2023-01-12 02:45:31
国内常用的js类库大全(CDN公共库)
2024-05-11 10:23:29
Python使用内置json模块解析json格式数据的方法
2023-07-30 14:10:45

Python的Flask框架中的Jinja2模板引擎学习教程
2022-05-28 10:26:08
js更好地截取字符串
2008-03-11 19:00:00
Oracle数据库下载及安装图文操作步骤
2024-01-26 11:15:49

Python jieba结巴分词原理及用法解析
2023-08-29 17:43:36

css基础教程属性篇之盒子模型
2008-07-29 12:05:00

ajax实现Dig程序中的投票
2008-01-22 17:27:00

python 还原梯度下降算法实现一维线性回归
2023-10-09 21:53:42

Python实现打乒乓小游戏
2023-07-20 04:48:53

python网络爬虫精解之正则表达式的使用说明
2023-02-26 17:13:21

PHP实现生成Excel文件并导出的示例详解
2023-05-28 13:11:18
Python利用scapy实现ARP欺骗的方法
2021-07-24 08:26:03

python 字典修改键(key)的几种方法
2021-01-05 16:58:00

[翻译]标记语言和样式手册 Chapter 14 图片替换
2008-02-18 12:56:00

Python中如何使用Matplotlib库绘制图形
2021-09-27 11:59:04

SQL server 管理事务和数据库介绍
2024-01-21 18:54:32
