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

    To iterate in reverse with an index (if that's what you want, and the criteria you are using to say it's better) then use range with reversed as stated in this answer; it's far simpler.

  2. loops - Traverse a list in reverse order in Python - Stack Overflow

    Feb 10, 2009 · How do I traverse a list in reverse order in Python? So I can start from collection[len(collection)-1] and end in collection[0]. I also want to be able to access the loop …

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

    How do I iterate over a list in reverse in Python? See also: How can I get a reversed copy of a list (avoid a separate statement when chaining a method after .reverse)?

  4. Best way to loop over a python string backwards

    Aug 9, 2015 · What is the best way to loop over a python string backwards? The following seems a little awkward for all the need of -1 offset: string = "trick or treat" for i in range(len(string)-1, 0 …

  5. python - Loop backwards using indices - Stack Overflow

    In Python 3, range behaves the same way as xrange does in 2.7. @hacksoi depends on the use case but let's say you're iterating backwards in a large buffer, let's say it's 10 MB, then creating …

  6. loops - How to enumerate over a list in python backwards with …

    Jun 13, 2021 · How to enumerate over a list in python backwards with index (From the end to the beginning) Asked 4 years, 6 months ago Modified 4 years, 6 months ago Viewed 16k times

  7. Need to iterate over a Python list in reverse as fast as possible

    Jul 14, 2012 · I'm using Python 3.2.3. What's the fastest way to iterate over a list in reverse? [::-1], reversed, list.reverse () or maybe some other way? I'm dealing with a list of about 5e6 …

  8. Iterate through a dictionary in reverse order (Python)

    May 23, 2016 · I understand that when iterating through a dictionary, it will be in arbitrary order. However, I need to make sure that one particular item is accessed last, and this item happens …

  9. python - Moving back an iteration in a for loop - Stack Overflow

    Jan 17, 2013 · In Python it's possible to set up a two-way exchange between an iterator (what comes after in in a for..in loop) and its consumer (code inside the loop). To achieve this, you …

  10. python - How to read a file in reverse order? - Stack Overflow

    How to read a file in reverse order using python? I want to read a file from last line to first line.