Better solution

Michael Hudson mwh at python.net
Wed Aug 21 05:41:10 EDT 2002


"Bo M. Maryniuck" <b.maryniuk at forbis.lt> writes:

> On Wednesday 21 August 2002 10:24, Michael Hudson wrote:
> > > Also what is [:]?
> > A slice.
> "a zlize". :-) Thank you, but I know this! What the advantage and different 
> between:
> 
[snip]

Consider:

>>> a = range(10)
>>> b = a     
>>> b = [x for x in b if x % 2 == 0]
>>> a, b
([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8])

versus:

>>> a = range(10)
>>> b = a
>>> b[:] = [x for x in b if x % 2 == 0]
>>> a, b
([0, 2, 4, 6, 8], [0, 2, 4, 6, 8])

Cheers,
M.

-- 
  There's an aura of unholy black magic about CLISP.  It works, but
  I have no idea how it does it.  I suspect there's a goat involved
  somewhere.                     -- Johann Hibschman, comp.lang.scheme



More information about the Python-list mailing list