About 121,000 results
Open links in new tab
  1. How do I reverse a string in Python? - Stack Overflow

    May 31, 2009 · Python: reverse a string. 3. Reversing a string in Python using a loop? 1. To reverse sentence in python ...

  2. What is the most efficient way to reverse a string in Python?

    Jun 26, 2023 · So, s[::-1] is the recommended way to reverse a string in Python because of its combination of efficiency, readability, and idiomatic Python style. Share Improve this answer

  3. python - How do I reverse a list or loop over it backwards? - Stack ...

    Oct 15, 2010 · I find (contrary to some other suggestions) that l.reverse() is by far the fastest way to reverse a long list in Python 3 and 2. I'd be interested to know if others can replicate these …

  4. Reverse a string in Python two characters at a time (Network byte …

    Here is a function based on the best, fastest, and most Pythonic answer above and in current Python 3 syntax: def reverse_hex(hex_string): if isinstance(hex_string, str): input_is_string = …

  5. python - Reverse string: string[::-1] works, but string[0::-1] and ...

    Feb 7, 2014 · Reverse string Python slice notation. 2. Slicing to reverse a string does not work in this case. 1. How ...

  6. Python reversing a string using recursion - Stack Overflow

    Literally the first thing? You get the last character of the string, right? So the reverse of a string is the last character, followed by the reverse of everything but the last character, which is where …

  7. python - Understanding string reversal via slicing - Stack Overflow

    The "-1" part represents the "step" part of the slicing—in this case, it goes through the string 1 character at a time, but backwards (a negative step means start from the end of the string). If …

  8. Best way to loop over a python string backwards

    Aug 9, 2015 · Less code is usually faster in Python. Luckily, you don't have to guess: python -mtimeit -s"s='x'*100000" "for x in s[::-1]: pass" 100 loops, best of 3: 1.99 msec per loop python …

  9. Fastest way to reverse a string in python - Stack Overflow

    Apr 30, 2016 · I was able to come up with two different ways to reverse a string in Python. Common sense dictates that code with more lines should run slower. I reversed a the string in …

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

    May 21, 2017 · That's not in-place; you're just reversing the order of the letters in each word. "In place" has a very specific meaning when it comes to data structures; it means you're …

Refresh