On Wed, Sep 1, 2010 at 6:45 PM, Matt Saxton <m...@scotweb.co.uk> wrote:
> On Wed, 1 Sep 2010 09:00:03 -0400 > Victor Subervi <victorsube...@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) > > > Also, is there a way to append to > > the front of the list directly? > > TIA, > > beno > > The insert() method can do this, i.e. > >>> cols.insert(0, 'Delete') > > -- > Matt Saxton <m...@scotweb.co.uk> > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf
-- http://mail.python.org/mailman/listinfo/python-list