Skip to content

reverse() returns None #147

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

Closed
ladyada opened this issue Jun 5, 2017 · 3 comments
Closed

reverse() returns None #147

ladyada opened this issue Jun 5, 2017 · 3 comments

Comments

@ladyada
Copy link
Member

ladyada commented Jun 5, 2017

>>> ledpins = [0, 1, 2]
>>> ledpins.reverse() -> None
>>> ledpins[::-1] -> [2, 1, 0]

I prefer reverse() for readability, but for now am using [::-1]

@dhalbert
Copy link
Collaborator

dhalbert commented Jun 5, 2017

reverse() reverses a list in place, and deliberately does not return anything, to remind you it's not a function, but something with a side-effect.

>>> l = [1,2,3]
>>> l.reverse()
>>> l
[3, 2, 1]

If you want a functional operation, use list.reversed(). Scott recently took a pull request from me that turned that on in CircuitPython, as well as some other things: #138.

@ladyada
Copy link
Member Author

ladyada commented Jun 5, 2017

oh weird! i think maybe i didnt have reversed() and got a confused :)

@ladyada ladyada closed this as completed Jun 5, 2017
@tannewt
Copy link
Member

tannewt commented Jun 5, 2017

Just a note, its reversed(l) rather than l.reversed(). Docs are here. l.sort() and sorted(l) work this way too.

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

No branches or pull requests

3 participants