About 3,000,000 results
Open links in new tab
  1. Reverse Words in a Given String in Python - GeeksforGeeks

    Jan 6, 2025 · Using split () and join () is the most common method to reverse the words in a string. The split() method splits the string into a list of words. [::-1] reverses the list of words. …

  2. Reverse individual words - GeeksforGeeks

    Mar 17, 2025 · To reverse individual words in a string, we can use built-in functions like stringstream in C++, S tringBuilder in Java, split in Python and other languages. After splitting …

  3. python - Reverse each word in a string - Stack Overflow

    May 27, 2017 · A version without Python-level looping and with reversing the whole string once instead of each word separately. def reverseEachWord(s): return " ".join(s[::-1].split()[::-1]) …

  4. How do I reverse words in a string with Python - Stack Overflow

    May 21, 2017 · re is python's regex module, and re.sub is the function in that module that handles substitutions. It has three required parameters. The first is the regex you're matching by. In …

  5. Reverse each word in a sentence in Python - GeeksforGeeks

    Nov 20, 2024 · We can simply use a loop (for loop) to reverse each word in a sentence. Explanation: s.split () breaks the sentence into words. Use ” “.join () to join the reversed words …

  6. python - How to reverse the order of the words in a string - Stack Overflow

    You can use split to get the separate words, reverse to reverse the list, and finally join to join them again to make the final string: s = "This is New York" # split first a = s.split() # reverse list …

  7. How to Reverse Words in a String in Python - CodeSpeedy

    There are various ways to reverse a string like reversed() function, using [::-1] to print in the reversed order or using the reverse() method. Each one has it’s own usage, advantages and …

  8. Reverse Each Word in a String Using Python | Step-by-Step Guide

    Learn how to reverse each word in a string in Python using methods like split (), join (), and slicing with clear, easy-to-follow examples.

  9. Python Program To Reverse Words In A Given String

    May 5, 2023 · Reverse Words in a String Using Two-Pointer Approach. Reverse the entire string. Reverse each word in the reversed string. Steps: Start by taking the input string as s. Reverse …

  10. 5 Best Ways to Reverse the Position of Each Word of a Given String

    Mar 10, 2024 · Python’s slicing syntax has a powerful feature that allows for reversing lists and strings. You can reverse the words in a sentence with a one-liner using this slicing trick. Here’s …

Refresh