Negative step changes a way, slice notation works. It makes the slice be built from the tail of the list. So, it goes from the last element to the first element. So [-1:1:-1] will start from last element of the list and will end end at 2nd element of list, thus as 0th and 1st are sliced we will be left with 7 elements
YOu maybe understand better with this example:
>>> list1=[i for i in range(1,10)]
>>> list1
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list2=list1[-1:1:-1]
>>> list2
[9, 8, 7, 6, 5, 4, 3]
upvoted 21 times
...
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Avidulam
Highly Voted 3 years, 9 months agoshilpadk
Most Recent 1 year agonaveenbv80
1 year, 12 months agomacxsz
2 years, 7 months agochr000
4 years, 3 months agokauser
4 years, 3 months agoEfren
3 years, 7 months ago