[Tutor] DeleteNode

Daniel Yoo dyoo@hkn.EECS.Berkeley.EDU
Fri, 14 Jul 2000 13:39:21 -0700 (PDT)


On Fri, 14 Jul 2000, Vanessa Green wrote:

> I have a question concerning how to delete a node using python.  I am
> new to programming and python is the first language that I am slowly
> learning.  Would you please let me know the best way to go about
> deleting a node that contains both strings and integers.  Also is it
> neccessary for me to create a key.

Hello!  Can you explain what you mean by a node?  I'm familiar with the
term 'node' when it's applied to linked-lists, but since you're doing
beginning programming, I'm not sure if that's what you mean.  I'll try to
guess what you mean, but if I starts sounding silly, you can ignore
me.  *grin*


If you mean an element in a hashtable like:

  names_ages = { "al" : 23, "sandy" : 29, "goofy" : 3 }

then the way to remove 'goofy' from the hashtable is to use the 'del'
operator.

  del names_ages["goofy"]

If you do this, names_ages will just contain values for 'al' and 'sandy':

  >>> names_ages
  {'sandy': 29, 'al': 23}


Oh, when you reply, make sure you reply to tutor@python.org.  (I haven't
been able to figure out how to fix 'reply-to' in pine yet.)