list comprehension question

John Gordon gordon at panix.com
Wed Feb 29 12:08:30 EST 2012


In <mailman.298.1330534919.3037.python-list at python.org> James Broadhead <jamesbroadhead at gmail.com> writes:

> On 29 February 2012 13:52, Johann Spies <johann.spies at gmail.com> wrote:
> > In [82]: t.append(instansie)
> > t.append(instansie)
> >
> > In [83]: t
> > t
> > Out[83]: ['Mangosuthu Technikon']

> > In [84]: t = [x.alt_name for x in lys].append(instansie)
> > t = [x.alt_name for x in lys].append(instansie)
> >
> > In [85]: t
> > t
> >
> > In [86]: type t
> > type t
> > -------> type(t)
> > Out[86]: NoneType
> >

> You should note that in [82], you're not doing:
> > t = t.append(instansie)

append() modifies the list in-place.  It doesn't return anything.
(and therefore its return value is None)

>>> x = [1, 2, 3]
>>> y = x.append(4)
>>> print x
[1, 2, 3, 4]
>>> print y
None

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list