One task that you need to do in your day-to-day work is to reverse a list.
One of the most common ways you can do that is by calling the reverse() method:
There are also other methods that help you do just that. You can of course stick to what you already know so far, but why not learn something new today?
One such way is by using negative slicing, which is surprisingly not that much talked about.
All you have to do is use colons and -1 and you are then going to be able to revert the list:
Yes, it’s that simple.
You have probably heard about finding the last element of a list using -1, but maybe you have missed this one, so here it comes.
That’s pretty much for this quick tip. I hope you find it useful.