华为机考入门python3--(13)牛客13-句子逆序

分类:列表

知识点:

  1. 列表逆序(和字符串逆序是一样的) my_list[::-1]

题目来自【牛客】

python 复制代码
def reverse_sentence(sentence):  
    # 将输入的句子分割
    words = sentence.split()  
    # 将单词逆序排列  
    words = words[::-1]  
    # 将单词用空格连接起来,并添加一个空格在最后  
    reversed_sentence = ' '.join(words)
    return reversed_sentence

input_str = input().strip()
print(reverse_sentence(input_str))

by 软件工程小施同学

相关推荐
NAGNIP1 小时前
GPT-5.1 发布:更聪明,也更有温度的 AI
人工智能·算法
NAGNIP1 小时前
激活函数有什么用?有哪些常用的激活函数?
人工智能·算法
元亓亓亓2 小时前
LeetCode热题100--416. 分割等和子集--中等
算法·leetcode·职场和发展
BanyeBirth2 小时前
C++差分数组(二维)
开发语言·c++·算法
xu_yule4 小时前
算法基础(数论)—算法基本定理
c++·算法·算数基本定理
CoderCodingNo4 小时前
【GESP】C++五级真题(结构体排序考点) luogu-B3968 [GESP202403 五级] 成绩排序
开发语言·c++·算法
YGGP5 小时前
【Golang】LeetCode 32. 最长有效括号
算法·leetcode
自然常数e6 小时前
字符函数和字符串函数
c语言·算法·visual studio
leaves falling6 小时前
c语言分数求和
算法