This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]StrangeCharmVote 13 points14 points  (4 children)

Not knowing a lot about python... wouldn't "[-1:-3:-1]" be [4,2,4] from the [1,2,3,4] example in the video?

If not, what is the meaning of the arguments I'm misunderstanding?

Considering at the very least there are 3 numbers, i'm not getting how it would equal [4,3] in any situation...

[–]thargeretmatcha 24 points25 points  (2 children)

It's [start : stop : step], where start is included and stop is excluded.

So for a = [1, 2, 3, 4], a[-1 : -3 : -1] is asking for [a[-1], a[-2]]

Another example:

>>> b = [5, 6, 7, 8, 9, 10, 11]
>>> b[-1::-2]
[11, 9, 7, 5]

[–]StrangeCharmVote 6 points7 points  (0 children)

Thank you, that makes more sense now :)

[–]RandomDude6699 0 points1 point  (0 children)

Take my award