[Tutor] Deleting an entry from a dictionary

Adam Bark adam.jtm30 at gmail.com
Tue Aug 2 23:16:30 CEST 2005


meals.pop(key) will do it.
Example:
>>> meals = {}
>>> meals['breakfast'] = 'slimfast'
>>> meals['lunch'] = 'slimfast'
>>> meals['dinner'] = 'something sensible'
>>> meals
{'lunch': 'slimfast', 'breakfast': 'slimfast', 'dinner': 'something 
sensible'}
>>> meals.pop("breakfast")
'slimfast'
>>> meals
{'lunch': 'slimfast', 'dinner': 'something sensible'}

On 8/2/05, Greg Lindstrom <greg.lindstrom at novasyshealth.com> wrote:
> 
> Hello-
> 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'?
> 
> Thanks!
> --greg
> 
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050802/f89233db/attachment.htm


More information about the Tutor mailing list