a=[1,2,3,4].reverse() - why "a" is None?

Xavier Ho contact at xavierho.com
Mon Oct 12 03:25:52 EDT 2009


Nadav, it's because reverse() modifies the list in-place. I've gotten this
gotcha many times,

If you had done:

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

Or even better:

>>> a = [1,2,3,4][::-1]
>>> a
[4, 3, 2, 1]

Cheers,
Xav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091012/0c4416bf/attachment-0001.html>


More information about the Python-list mailing list