Reversing a List

Shashank Singh shashank.sunny.singh at gmail.com
Wed Sep 1 15:17:34 CEST 2010


reverse reverses in-place

>>> l = [1, 2, 3]
>>> r = l.reverse()
>>> r is None
True
>>> l
[3, 2, 1]
>>>


On Wed, Sep 1, 2010 at 6:30 PM, Victor Subervi <victorsubervi at gmail.com>wrote:

> Hi;
> I have this code:
>
>   cursor.execute('describe products;')
>   cols = [item[0] for item in cursor]
>   cols = cols.reverse()
>   cols.append('Delete')
>   cols = cols.reverse()
>
> Unfortunately, the list doesn't reverse. If I print cols after the first
> reverse(), it prints None. Please advise. Also, is there a way to append to
> the front of the list directly?
> TIA,
> beno
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Regards
Shashank Singh
Senior Undergraduate, Department of Computer Science and Engineering
Indian Institute of Technology Bombay
shashank.sunny.singh at gmail.com
http://www.cse.iitb.ac.in/~shashanksingh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100901/567c08db/attachment.html>


More information about the Python-list mailing list