13
Showerthought: my first real function actually worked on the third try
I was stuck for an hour trying to get a list of names to print in reverse order, and my code kept crashing. I finally looked up a guide from a site called freeCodeCamp and used a simple for loop with a negative step. Has anyone else found a good trick for working with lists backwards?
2 comments
Log in to join the discussion
Log In2 Comments
martinez.diana11d agoTop Commenter
Yeah, that negative step loop is a lifesaver. I mean, I always forget the syntax and have to look it up again. Another thing that works for me is using reversed() if you just need to go through the list once. It's cleaner sometimes, idk. But honestly, printing stuff backwards used to make my brain hurt until I just started writing it down on paper first.
1
olivia38011d ago
Honestly, it's just printing a list backwards. Is it really that big of a deal to need a lifesaver? I get that the syntax can be tricky at first, but after a few times it sticks. Writing it down on paper seems like overkill for something this small. It's a simple loop, not brain surgery.
1