python3倒叙字符串

google测试工程师的一道题:
设计一个函数,使用任意语言,完成以下功能:
一个句子,将句子中的单词全部倒排过来,但单词的字母顺序不变。比如,This is a real world,输出结果为
world real a is this.

下面利用python来实现:

句子为:

 1 #!/usr/bin/env python3.4
 2 # -*- coding: utf-8 -*-
 3
 4 #某一段文字
 5 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."
 6
 7 #按照空格分割
 8 strings = data.split()
 9 arr = []
10
11 #打印出来
12 for string in strings:
13     arr.append(string)
14
15 #将文本倒叙
16 arr.reverse()
17 # 按照空格将文本变为字符串
18 newstring = " ".join(arr)
19
20 print(newstring)

结果:

时间: 2024-08-29 11:42:00

python3倒叙字符串的相关文章

【leetcode80】Reverse Vowels of a String(元音字母倒叙)

题目描述: 写一个函数,实现输入一个字符串,然后把其中的元音字母倒叙 注意 元音字母包含大小写,元音字母有五个a,e,i,o,u 原文描述: Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Given s = "hello", return "holle". Example 2: Given s = "leet

python3学习之字符串

s='this is test message' s.capitalize()    首字母大写,其它小写 s.find(sub[, start[, end]])      在指定范围内(默认全部字符串),查找sub是否包含在字符串中,包含时                                             返回第一次匹配的index,否则返回-1 s.rfind(sub[, start[, end]])    在指定范围内(默认全部字符串),查找sub是否包含在字符串中,

angularjs ng-repeat倒叙

<div ng-app="myApp" ng-controller="customersCtrl"> <table> <tr ng-repeat="x in names|orderBy:'Country'| reverse"> <td>{{ x.Name }}</td> <td>{{ x.Country }}</td> </tr> </table

python实现列表倒叙打印

def func(listNode): listNode.reverse() for i in listNode: print(i) li = [1,2,3,4,5] func(li) 利用python列表函数reverse()将列表倒叙,然后遍历打印,但是这有一个缺点就是改变了原列表的顺序.看看下面的代码: def func(listNode): array = listNode[::-1] for i in array: print(i) li = [1,2,3,4,5] func(li)

(译)MySQL 8.0实验室---MySQL中的倒叙索引(Descending Indexes)

译者注:MySQL 8.0之前,不管是否指定索引建的排序方式,都会忽略创建索引时候指定的排序方式(语法上不会报错),最终都会创建为ASC方式的索引,在执行查询的时候,只存在forwarded(正向)方式对索引进行扫描.关于正向索引和反向索引,逻辑上很容易理解,这里有两个相关的概念:正向索引或者反向索引,两者都是在构建B树索引时候的相关字段排序方式,是B索引树的逻辑存储方式正向扫描(forward)和反向扫描( Backward index scan;)是执行查询的过程中对B树索引的扫描方式,是数

vue点击按钮给商品按照价格进行倒叙

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" con

Python3.7之字符串

Python3.7之字符串 一.基础知识 在python中,加了引号的字符均被认为是字符串.单双引号没有任何区别,但要考虑字符串内含有引号的配合情况,多行字符串必须用多引号. 二.字符串常用函数 1.合并字符串之join()与format() join():用于将序列中的元素以指定的字符连接生成一个新的字符串. l = ['a','a','a','a'] L1 = ''.join(l) # output is 'aaaa' L2 = 'b'.join(l) # output is 'ababab

一月十日练习习题,1数组数据存入字典并输出2降序 和倒叙 输出数组中内容3对字符串当中信息进行查找是否存在4 把数组当中信息尽心中文排序

// //  main.m //  Pratise_Jan10_1 // //  Created by wangyang on 16/1/10. //  Copyright (c) 2016年 Wangyang. All rights reserved. // #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { /* 第1题 请将如下数据存储成字典,并将字典

将整形整数转化为数组的形式分别依次存到数组当中,然后倒叙输出、把原本字符串倒序输出。截取字符串等等

// //  main.m //  ClassWork.m // //  Created by FuHeXiang on 16/1/9. //  Copyright (c) 2016年 FuHeXiang. All rights reserved. // #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSLog(@"第1题——————————