About 1,690,000 results
Open links in new tab
  1. iteration - How to loop backwards in python? - Stack Overflow

    def reverse(text): # Container for reversed string txet="" # store the length of the string to be reversed # account for indexes starting at 0 length = len(text)-1 # loop through the string in …

  2. Backward iteration in Python - GeeksforGeeks

    Nov 20, 2024 · Python provides various methods for backward iteration, such as using negative indexing or employing built-in functions like reversed(). Use reversed () method when we …

  3. Two Simple Ways to Count Backwards in Python - Medium

    May 18, 2020 · The most basic method of counting backwards is to use a counting variable inside of a while loop. We need three definitions in order to count backwards: the starting point, how to...

  4. python - How to count down in for loop? - Stack Overflow

    Mar 27, 2015 · If you need to traverse the iterable in reverse order, you would do: for l in letters[::-1]: print(l) When for any reason you need the index, you can use enumerate: for i, l in …

  5. python - Counting backwards - Stack Overflow

    May 26, 2011 · This question shows how to iterate over a list using a sliding window. The rest should be simple enough. Create a sliding window, and test on that: iterator = iter(iterable) …

  6. Top 5 Methods to Loop Backwards Using Indices in Python

    Dec 5, 2024 · Explore various effective techniques to loop backwards using indices in Python for optimal readability and performance.

  7. Loop backward in Python - Techie Delight

    Apr 13, 2024 · This post will discuss how to loop backward in Python. 1. Using range() function. The Pythonic approach to iterate backward in Python is using the range constructor with step …

  8. How to Loop Through a List Backwards in Python - Tutorial Kart

    To loop through a list backwards in Python, you can use methods like reversed(), slicing ([::-1]), the range() function, or the iter() function with reversed().

  9. Top 4 Ways to Loop Backwards in Python - sqlpey

    Dec 5, 2024 · If you’re seeking an efficient way to perform backward loops in Python, consider these top four techniques: 1. Using the reversed() Function. The reversed() function provides …

  10. python - Loop backwards using indices - Stack Overflow

    Jan 4, 2023 · class Reverse: """Iterator for looping over a sequence backwards""" def __init__(self, seq): self.seq = seq self.index = len(seq) def __iter__(self): return self def …

  11. Some results have been removed
Refresh