Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition in list indexing related to negative step #782

Open
linnabraham opened this issue Jul 19, 2024 · 4 comments
Open

Addition in list indexing related to negative step #782

linnabraham opened this issue Jul 19, 2024 · 4 comments

Comments

@linnabraham
Copy link

linnabraham commented Jul 19, 2024

In https://lectures.scientific-python.org/intro/language/basic_types.html#lists it is mentioned that all slicing parameters are optional. And a few examples are shown to demonstrate what values are implicitly set when you skip these.

However the examples miss a case with negative step value. With a negative step value, the start is implicitly set to -1. Which differs from positive step value cases, where if the start is skipped, the start index is implicitly set to 0.

Although negative step is demonstrated later on, it is just with regarding to reversing a list. This aspect is not made clear there.
Maybe this can also be a warning or something.?

@stefanv
Copy link
Member

stefanv commented Jul 19, 2024

Thanks for reporting; it's about time we give this material another review.

@linnabraham
Copy link
Author

How does one contribute to the material? Is it enough to report any such issue or would it be better to make a pull request?

@rossbar
Copy link
Contributor

rossbar commented Jul 22, 2024

FWIW I think the case you describe is sufficiently illustrated in the third example under the Lists heading. However, please feel free to open PRs with suggestions!

@linnabraham
Copy link
Author

@rossbar Thanks for letting me know that PRs are welcome.

If you were pointing to this colors[-1], that is not the case I meant. Here you are explicitly indexing using a negative index and hence its clear. But suppose you use the start:stop:step with colors[::-1] or colors[::-2] the start and end indices are omitted but implicitly the start is set to -1. That is colors[-1::-1] or colors[-1::-2] would give identical results. This thing that happens under the hood is not clear to the reader, in my opinion, when this example is listed further down as an example of list reversing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants