filmov
tv
How to create a reversed copy of a list using reverse slicing in Python | Shorts

Показать описание
In this quick Python video, we'll learn how to use reverse slicing to create a reversed copy of a list.
========================================
You can easily create a reversed copy of a list using Python’s slicing syntax. Placing a single colon inside square brackets slices the entire list, this means that you will end up with a new list that is a copy of the original one. Slicing returns a new list, so this means that these are 2 different lists that just have the same values.
To create a copy where the items are reversed, add another colon followed by -1. This will copy all the items starting from the end of the original list. So now we have the original list, which remains unchanged. And then this other list, where the items are in reverse.
==============================
#PythonShorts #PythonTips
========================================
You can easily create a reversed copy of a list using Python’s slicing syntax. Placing a single colon inside square brackets slices the entire list, this means that you will end up with a new list that is a copy of the original one. Slicing returns a new list, so this means that these are 2 different lists that just have the same values.
To create a copy where the items are reversed, add another colon followed by -1. This will copy all the items starting from the end of the original list. So now we have the original list, which remains unchanged. And then this other list, where the items are in reverse.
==============================
#PythonShorts #PythonTips