# Leetcode 557 反转字符串中的单词III
### 题目描述

给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序。

**示例1:**

输入: "Let's take LeetCode contest"
输出: "s'teL ekat edoCteeL tsetnoc"

 

class Solution:
    def reverseWords(self, s: str) -> str:
        ls = s.split()
        for i,s in enumerate(ls):
            ls[i] = s[::-1]
        return " ".join(ls)

 

enumerate():可以同时列出 可遍历的数据对象(如列表、元组或字符串)的下标和数据。

leetcode python反转字符串中的单词

相关文章:

  • 2021-11-21
  • 2022-12-23
  • 2021-06-08
  • 2021-05-15
猜你喜欢
  • 2021-07-10
  • 2021-12-05
  • 2021-08-16
  • 2022-01-04
  • 2021-06-20
  • 2021-08-21
相关资源
相似解决方案