[Tutor] Deleting an entry from a dictionary

Jay Loden python at jayloden.com
Wed Aug 3 12:28:49 CEST 2005


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 the zero index, or use list.reverse() with list.append() to 
flip the list around, add an item, then reverse it back to the original order 
with one new item at the beginning. 

-Jay

On Wednesday 03 August 2005 2:21 pm, Smith, Jeff wrote:
> 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.
>
> Jeff
>


More information about the Tutor mailing list