org
Subject: Re: [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]; d
From: Kent Johnson [mailto:[EMAIL 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.
&
I don't believe it does...some time ago I asked about this when I was creating
a list and I wanted the opposite of list.append() - if you search "prepend to
a list" you should find the responses I was sent.
The only solutions Python offers that I'm aware of are to either use
list.insert() at t
lto:[EMAIL 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
>
+jsmith=[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(key) will do
it.Example:>>> meals = {}>>> meals[
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.
val = mylist.pop(0)
Kent
_
(val, mylist) =
(mylist[0], 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
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
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
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 onl
10 matches
Mail list logo