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)
结果:
python3倒叙字符串的更多相关文章
- Python3 编程之字符串处理
Python3 编程之字符串处理 在编程中最常见的任务就是字符串的处理,So,学好字符串的使用非常重要 一.变量的定义规范 Python中声明变量时,要符合以下规则为准: 只能使用数字.字母.下划线组 ...
- 【leetcode80】Reverse Vowels of a String(元音字母倒叙)
题目描述: 写一个函数,实现输入一个字符串,然后把其中的元音字母倒叙 注意 元音字母包含大小写,元音字母有五个a,e,i,o,u 原文描述: Write a function that takes a ...
- JS使用Enter事件将输入的字符倒叙输出
在JavaScript中执行当用户按下Enter键位时将用户输入的字符倒叙输出! HTML代码: <body> <form id="form1" runat=&q ...
- Python3中的字符串函数学习总结
这篇文章主要介绍了Python3中的字符串函数学习总结,本文讲解了格式化类方法.查找 & 替换类方法.拆分 & 组合类方法等内容,需要的朋友可以参考下. Sequence Types ...
- Java知识积累2-StringReverse实现文字(单词)倒叙输出
package String; import java.util.Stack;import java.util.StringTokenizer; public class StringReverse ...
- 【java基础学习一】int[]、Integer[]、String[] 排序( 正序、倒叙)、去重
调用: //重复项有9.5.1.2 int[] ints = new int[]{9,4,7,8,2,5,1,6,2,5,9,1}; arrayIntTest(ints); ///////////// ...
- js操作table倒叙显示序号的问题
今天遇到一奇葩问题,就是在js添加table时,序号是倒叙显示的,而且数据库查出来时正序的,为什么显示是倒叙的呢? 我百度一番,终于有了结果: var newRow=table.insertRow(- ...
- Python2和Python3中的字符串编码问题解决
Python2和Python3在字符串编码上是有明显的区别. 在Python2中,字符串无法完全地支持国际字符集和Unicode编码.为了解决这种限制,Python2对Unicode数据使用了单独的字 ...
- python实现列表倒叙打印
def func(listNode): listNode.reverse() for i in listNode: print(i) li = [1,2,3,4,5] func(li) 利用pytho ...
随机推荐
- 解决远程桌面链接时出现"The RPC server is unavailable."或"RPC服务器不可用"的问题
解决远程桌面链接时出现"The RPC server is unavailable."或"RPC服务器不可用"的问题 解决远程桌面链接时出现"The ...
- Linux交叉开发环境搭建 —— 效率之源
楼主今天终于把所有Linux开发环境需要的软件下载完毕了.虽然以前也是搭建过的,时间久了又折腾了一晚上. 交叉环境: Windows.Linux文件共享 SecureCRT 连接虚拟机终端 工具: V ...
- LCA(RMQ)
; xh=; ..lx*] of longint; lt,dfn,fr,dep:..lx] of longint; f:..lx*,..xh] of longint; vis:..lx] of boo ...
- wcf之OperationContextScope
作用:使用消息头向服务发送额外的信息. 1.客户端代码如下: namespace Client { class Program { static void Main(string[] args) { ...
- Objective-C对象初始化 、 实例方法和参数 、 类方法 、 工厂方法 、 单例模式
1 重构Point2类 1.1 问题 本案例使用初始化方法重构Point2类,类中有横坐标x.纵坐标y两个属性,并且有一个能显示位置show方法.在主程序中创建两个Point2类的对象,设置其横纵坐标 ...
- tensorflow0.8.0 安装配置
参考官网:https://www.tensorflow.org/ Ubuntu15.10 + Eclipse Mars.2(4.5.2)官网最新 + Anaconda3-4.0.0 + Pydev4 ...
- Xen虚拟机磁盘镜像模板制作(三)—CentOS 7
这里整理下制作Xen CentOS 7磁盘镜像模版的流程: 1.创建一个将要用来安装CentOS 7系统的LV,命令如下: [root@localhost ~]# lvcreate -L 5G -n ...
- HTTP 简介
HTTP 简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传 ...
- Codeforces Round #365 (Div. 2) A 水
A. Mishka and Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Linux驱动设计——字符设备驱动(一)
Linux字符设别驱动结构 cdev结构体 struct cdev { struct kobject kobj; struct module *owner; const struct file_ope ...