scottmiller42, to python
@scottmiller42@mstdn.social avatar

It's really a bummer that enumerate doesn't have an option to tell it to go backwards.

Also, it took me way too long to figure out that code like this doesn't do what I wanted it to do. (The index doesn't match the location in MyString.)

MyString = "Hello"
for index , Char in enumerate (MyString[::-1]):
print (index, Char)

0 o
1 l
2 l
3 e
4 H

scottmiller42,
@scottmiller42@mstdn.social avatar

I did find some proposed solutions that involve reversing a generator function and ... bleh. They may be a little more efficient, but none pleased my eye as much as just reversing the range function, like this:

MyString = "Hello"
for index in range (len(MyString)-1, -1, -1):
print (index, MyString[index])

  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • mdbf
  • ngwrru68w68
  • modclub
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • InstantRegret
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • DreamBathrooms
  • JUstTest
  • normalnudes
  • osvaldo12
  • tester
  • GTA5RPClips
  • cubers
  • everett
  • tacticalgear
  • ethstaker
  • provamag3
  • anitta
  • Leos
  • cisconetworking
  • lostlight
  • All magazines