Reversing a List

Victor Subervi victorsubervi at gmail.com
Thu Sep 2 20:51:04 CEST 2010


On Wed, Sep 1, 2010 at 9:26 AM, Shashwat Anand <anand.shashwat at gmail.com>wrote:

>
>
> On Wed, Sep 1, 2010 at 6:45 PM, Matt Saxton <matt at scotweb.co.uk> wrote:
>
>> On Wed, 1 Sep 2010 09:00:03 -0400
>> 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.
>>
>> The reverse() method modifies the list in place, but returns None, so just
>> use
>> >>> cols.reverse()
>>
>> rather than
>> >>> cols = cols.reverse()
>>
>
> Alternatively you can do \,
>
> >>>cols = reversed(cols)
>

Thanks again, all
beno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100902/94bbf712/attachment.html>


More information about the Python-list mailing list