:3
Everything is barely weeks. Everything is days. We have minutes to live.
- about me
- Github: @r1bb1t-h0l3
Everything is barely weeks. Everything is days. We have minutes to live.
Reversing a list is a common operation, especially in algorithmic problem-solving and data manipulation. Even though Python provides simple, built-in ways to reverse a list, since I am specifically trying to improve my algorithmic thinking and logical reasoning skills, I am focussing on purely algorithmic reversal. Specifically I am doing this as prep to solving a DMOJ problem I am working on which I will share a bit later.
So here are the three different ways I found to reverse a list in Python without using any built-in methods like .reverse()
or slicing ([::-1])
. They all make sense to me, so hopefully as I get a little more practise implementing them the logic will start to feel second nature. My favourite is the last one with modulo and floor division, as the second one still feels a bit like “python magic” with tuple unpacking being used and the first one is range(len)
magic.
Posted · Author ribbit