[Tutor] Deleting an entry from a dictionary

Smith, Jeff jsmith at medplus.com
Wed Aug 3 16:21:46 CEST 2005

Ummm...that doesn't do what I asked.

pop is a linguistic idiom for

(val, mylist) = (mylist[-1], mylist[0:-1])

shift is the standard idiom for 

(val, mylist) = (mylist[0], mylist[1:])

but Python doesn't appear to offer this.


-----Original Message-----
From: Kent Johnson [mailto:kent37 at tds.net] 
Sent: Wednesday, August 03, 2005 9:15 AM
Cc: tutor at 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() =>    (val, mylist) = (mylist[0], mylist[1:])
> which seems a little clumsy.

val = mylist.pop(0)


Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list