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 ...
随机推荐
- 【LeetCode OJ】Surrounded Regions
Problem Link: http://oj.leetcode.com/problems/surrounded-regions/ We can do follows in the 2D board. ...
- VBS_For Each...Next
For Each...Next 循环与 For...Next 循环类似.For Each...Next 不是将语句运行指定的次数,而是对于数组中的每个元素或对象集合中的每一项重复一组语句.这在不知道集 ...
- 破解 crackme(完全拆解警告窗口)
系统 : Windows xp 程序 : crackme 程序下载地址 :http://pan.baidu.com/s/1kUrbcAr 要求 : 注册机编写 & 去除Nag窗口 使用工具 : ...
- VirtualizingStackPanel
<FlipView x:Name="flipView1" ItemsSource="{Binding}" ScrollViewer.HorizontalS ...
- 转:【More Effective C#】Lambda表达式优化
http://www.cnblogs.com/kongyiyun/archive/2010/10/19/1855274.html 使用Lambda表达式将会造成Lambda表达式主题部分的代码重复. ...
- php <? ?> <?php ?>
/******************************************************************** * php <? ?> <?php ?&g ...
- 学学数据库,记记sql
(1)Truncate 和 Drop 和 Delete 1. TRUNCATE TABLE 在功能上与不带 Where 子句的 Delete 语句相同:二者均删除表中的全部行.但 TRUNCATE T ...
- JavaScript数据结构——集合、字典和散列表
集合.字典和散列表都可以存储不重复的值. 在集合中,我们感兴趣的是每个值本身,并把它当作主要元素.在字典和散列表中,我们用 [键,值] 的形式来存储数据. 集合(Set 类):[值,值]对,是一组由无 ...
- [转载]python 爬虫总结
1.基本抓取网页 get方法 import urllib2 url = "http://www.baidu.com" response = urllib2.urlopen(url) ...
- Myeclipse里导入jQuery.js 时出现错误打红叉的解决方法
http://www.jb51.net/softjc/215710.html 解决方案:如上图所示:右击 jquery-2.1.1.min.js -->MyEclipse --> ①先点击 ...