On Tue, 2 Aug 2005, Greg Lindstrom wrote:

> This must be simple, but for the life of me I can't figure out how to
> delete an entry from a dictionary.  For example,
>
> meals = {}
> meals['breakfast'] = 'slimfast'
> meals['lunch'] = 'slimfast'
> meals['dinner'] = 'something sensible'
>
> How do I eliminate 'lunch' from the dictionary so that I only have
> 'breakfast' and 'dinner'?


Hi Greg,

Actually, it isn't obvious at all, so don't be too discouraged.  The 'del'
statement should do the trick:

######
>>> d = {'a': 'Alpha', 'b' : 'Beta'}
>>> del d['a']
>>> d
{'b': 'Beta'}
######


Here's a reference list of all the things you can do to a dictionary:

    http://www.python.org/doc/lib/typesmapping.html


Good luck!

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to