Python: delete key from dictionary 

Joined:
04/09/2007
Posts:
565

January 02, 2010 16:37:13    Last update: January 02, 2010 16:37:57
Use the del operator to delete one key, or clear method to delete all keys:

>>> d = { 'a': 1, 'b': 2, 'c' : 3 }
>>> del d['f']
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
KeyError: 'f'
>>> del d['a']
>>> d
{'c': 3, 'b': 2}
>>> d.clear()
>>> d
{}
>>>
[ Comment  | Tags ]
 
Easy email testing with http://www.ximailstop.com