Why doesn’t this work in Python?
>>> print [0,1,0,1,1,0,1,1,1,0,1,1,1,1,0].reverse()
None
I expected to get back the list in reverse order.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want it to return a new list in reverse order, you can use
[::-1]As I’m still trying to understand the downvote, if it doesn’t matter that the original list gets changed, use @taskinoor’s answer, it’ll be faster.
However if you’re required to keep the original list unchanged, I suggest you to use
[::-1].outputs