Two important things: Firstly, the second two examples are slicing, not indexing.
Second off, slicing doesn't quite work how you think it does (assuming you think x[::-1] == reversed(x), which your post seems to imply). Creating a slice creates a copy of that list segment. Pythons memory model means you don't copy the contents itself, but you're creating more references to the objects in the copy at around 28 bytes an element. So if you're memory constrained, or working with really big lists, you should probably use generators - like reversed (because reversed(x) != x[::-1]; they're not even the same type).
Thank you for your observations! I didn't mean to imply that think x[::-1] == reversed(x), just that reversed is another way to reverse a list. It completely escaped my mind that slicing creates new lists, I've edited the post to include it :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Two important things: Firstly, the second two examples are slicing, not indexing.
Second off, slicing doesn't quite work how you think it does (assuming you think x[::-1] == reversed(x), which your post seems to imply). Creating a slice creates a copy of that list segment. Pythons memory model means you don't copy the contents itself, but you're creating more references to the objects in the copy at around 28 bytes an element. So if you're memory constrained, or working with really big lists, you should probably use generators - like reversed (because reversed(x) != x[::-1]; they're not even the same type).
Thank you for your observations! I didn't mean to imply that think x[::-1] == reversed(x), just that reversed is another way to reverse a list. It completely escaped my mind that slicing creates new lists, I've edited the post to include it :)