About 176,000 results
Open links in new tab
  1. How can I use enumerate to count backwards? - Stack Overflow

    May 17, 2018 · We can define utility function (in Python3.3+) from itertools import count def enumerate_ext(iterable, start=0, step=1): indices = count(start, step) yield from zip(indices, iterable) and use it directly like letters = ['a', 'b', 'c'] for index, letter in enumerate_ext(letters, start=len(letters) - 1, step=-1): print(index, letter) or write helper

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

    May 18, 2020 · We need three definitions in order to count backwards: the starting point, how to exit the loop, and how to modify the loop. Let’s set up a countdown timer from 10 to 0. We identify that the...

  3. Backward iteration in Python - GeeksforGeeks

    Nov 20, 2024 · Backward iteration in Python is traversing a sequence (like list, string etc.) in reverse order, moving from the last element to the first. Python provides various methods for backward iteration, such as using negative indexing or employing built-in functions like reversed().

  4. iteration - How to loop backwards in python? - Stack Overflow

    To reverse a string without using reversed or [::-1], try something like: 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 reverse and append each character # deprecate the length index while length>=0:

  5. Counting backward from an integer using Python range built

    Sep 21, 2015 · you should do: for c in range(10,-1,-1): print c alternatively, you can do: for c in reversed(range(10)): print c or: for c in sorted(range(10), reverse=True): print c

  6. How to Get Range Backwards in Python - Delft Stack

    Mar 4, 2025 · One of the simplest ways to iterate backwards in Python is by using the range() function with a negative step. The range() function allows you to specify a starting point, an endpoint, and a step value. By setting the step value to a negative number, you can easily create a sequence that counts down. Here’s how you can do it: Output:

  7. Python list (Array) methods | remove, insert, pop, reverse, count

    Aug 11, 2021 · Here are all of the methods of list objects: List Function in python 3. append (x) extend (iterable) insert (i, x) remove (x) pop ( [i]) clear () index (x [, start [, end]]) count (x) sort (key=None, reverse=False) reverse () copy ()

  8. How to Reverse a Range in Python - LearnPython.com

    Sep 7, 2022 · Learn how to reverse a range in Python using the range (), reversed (), and sorted () functions.

  9. Write A Program To Print Reverse Counting From 10 To 1 Using

    Mar 19, 2021 · In this post, we learn how to reverse a number using a while loop in python. Program. Output. step2: Accept a number i.e num. step3: Sum = 0. step4: reminder = num%10 sum = sum*10+reminder. num = num/10. step5: if num>0. step6: Display reverse number. Flow chart for a Reverse number. Summary. Hope this post is beneficial for you.

  10. How to Iterate Backwards in Python - Delft Stack

    Mar 11, 2025 · One of the simplest ways to iterate backwards in Python is by using the built-in reversed() function. This function returns an iterator that accesses the given sequence in the reverse order. It can be applied to any sequence type, including lists, tuples, and strings. Here’s how you can use the reversed() function: Output:

  11. Some results have been removed
Refresh