], mylist[1:])
which
seems a little clumsy.
Jeff
-Original Message-From:
[EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Adam
BarkSent: Tuesday, August 02, 2005 5:17 PMTo: Greg
LindstromCc: tutor@python.orgSubject: Re: [Tutor] Deleting
an entry from a dictionary
meals.pop
PROTECTED]] On Behalf Of Adam
BarkSent: Tuesday, August 02, 2005 5:17 PMTo: Greg
LindstromCc: tutor@python.orgSubject: Re: [Tutor] Deleting
an entry from a dictionary
meals.pop(key) will do
it.Example: meals = {} meals['breakfast']
= 'slimfast' meals['lunch'] = 'slimfast'
meals['dinner
PROTECTED]
Sent: Wednesday, August 03, 2005 9:15 AM
Cc: tutor@python.org
Subject: Re: [Tutor] Deleting an entry from a dictionary
Smith, Jeff wrote:
Speaking of which, I note that there is a pop for lists but no shift.
Is there a Python idiom for this or is it just
val = mylist.shift
Subject: Re: [Tutor] Deleting an entry from a dictionary
Smith, Jeff wrote:
Speaking of which, I note that there is a pop for lists but no shift.
Is there a Python idiom for this or is it just
val = mylist.shift() =(val, mylist) = (mylist[0], mylist[1:])
which seems a little clumsy
: [Tutor] Deleting an entry from a dictionary
Smith, Jeff wrote:
Ummm...that doesn't do what I asked.
pop is a linguistic idiom for
(val, mylist) = (mylist[-1], mylist[0:-1])
No, actually, not quite.
From the docs:
s.pop([i]) same as x = s[i]; del s[i]; return x
so val = mylist.pop(0
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
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',