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 ...
随机推荐
- 学习笔记:只有一套app设计稿(5s尺寸)切出4和4s尺寸以及安卓系统主流尺寸的图
如何在只有一套app设计稿(5s尺寸)切出4和4s尺寸以及安卓系统主流尺寸的图 转自:http://www.zhihu.com/question/23255417 版权归原作者所有 目前ios手机 ...
- JavaScript 经常忽略的 7 个基础知识点
1. 在 String.prototype.replace 方法中使用 /g 和 /i标志位 令很多 JavaScript 初学者意外的是,字符串的 replace 方法并不会 替换所有匹配的子串—— ...
- magento问题集2
SQLSTATE[42S02]: Base table or view not found: 1146 Table XXXXXX 安装Galathemes.com theme插件. 首页无法打开,提示 ...
- magneto创建运费模板
Magento系统自带了大概7种运费方式:平价.运费表.免运费.ups.usps.fedex.dhl等.不过这些依然无法满足我们的需求,这时候就需要创建一个shipping module 来实现了.创 ...
- E - Power Strings,求最小周期串
E - Power Strings Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- notebook
1. 2.
- IE6 IE8下背景图片不显示问题
更改background:url()no-repeat; 去掉no-repeat即可解决问题!
- div+css总结—FF下div不设置高度背景颜色或外边框不能正常显示的解决方法(借鉴)
原地址:http://blog.sina.com.cn/s/blog_60b35e830100qwr2.html 在使用div+css进行网页布局时,如果外部div有背景颜色或者边框,而不设置其高度, ...
- Python编程小记
发现这种结构很实用: while True: expression .... if condition: expression break 好吧,我承认我是菜鸟-
- String的常规使用集合
今天先附上代码君: package com.jacob.javase; import java.io.UnsupportedEncodingException; /* *探讨String: * * ...