concise code (beginner)

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Sep 10 05:29:15 EDT 2007


"Lawrence D'Oliveiro" <ldo at geek-central.gen.new_zealand> wrote in
message
news:fbqo83$8fd$1 at lust.ihug.co.nz...

Why not just build a new list? E.g.

   newdevs = []
   for dev in devs :
       ...
       if not removing_dev :
           newdevs.append(dev)
       #end if
   #end for
   devs = newdevs

En Sun, 09 Sep 2007 22:58:54 -0300, bambam <david at asdf.asdf> escribi?:

I can try that, but I'm not sure that it will work. The problem
is that devList is just a pointer to a list owned by someone else.
Making devList point to a new list won't work: I need to make
the parent list different. I could do this by adding an extra
level of indirection, but I think at the risk making the call
environment more complex.

Then use [:] to *replace* all the old list items, do not merely rebind
the name. That last statement
should be, instead:

devs[:] = newdevs

(Please don't top-post)

--
Gabriel Genellina




More information about the Python-list mailing list