Get dict value but not as reference.

Jerry Hill malaclypse2 at gmail.com
Wed Jul 23 17:55:27 CEST 2008


On Wed, Jul 23, 2008 at 11:49 AM, Robert Rawlins
<robert.rawlins at thinkbluemedia.co.uk> wrote:
> I have a dictionary, and I want to get one of the values from it, but rather
> than returning it as a reference I want to actually detach/remove the
> element from the dictionary. Like so:

Use the pop() method of the dictionary, like this:

>>> my_dict = {'a': 'Item A', 'b': 'Item B', 'c': 'Item C'}
>>> my_dict.pop('a')
'Item A'
>>> my_dict
{'c': 'Item C', 'b': 'Item B'}
>>>

-- 
Jerry



More information about the Python-list mailing list