[Tutor] >> BANANAS! << Removing a class instance from a list?

Jose Amoreira amoreira@mercury.ubi.pt
Tue, 06 Mar 2001 15:28:17 +0000


Hello!

You can also remove list elements by position in the list, using del:
>>> lst = ['a','b','c']
>>> lst
['a', 'b', 'c']
>>> del lst[1]
>>> lst
['a', 'c']

Yet another possibility is to use the list.pop(i), wich returns and
deletes list[i].
Hope it helps!
So long
Ze
amoreira@mercury.ubi.pt


Chris McCormick wrote:

> [...]
>  So far, so good, right?  It's easy to append to the
> list.  The problem comes when I try to remove items
> from the list.  I'm supposed to use the value of the
> item I want to remove.  But what is the value of a
> class instance?  If I create two bananas and then
> print my list, I get something like this:
>
> [<flora.banana instance at 0081168C>, <flora.banana
> instance at 0081144C>]
>
> How do I feed that into banana.remove(listitemvalue)?
>
> Thanks in advance for your help.  We're being overrun
> here.
>
> - Chris
>
> PS - On the other hand, it's pretty cool to be able to
> say that I've crashed my computer with bananas. :-)