You can do the following:

_,v = d.popitem()

Or:

key, value = d.popitem()

Steve

On Mon, 14 Jun 2021 at 20:10, Greg Ewing <greg.ew...@canterbury.ac.nz>
wrote:

> On 14/06/21 4:19 am, BlindAnagram wrote:
> > Am I missing the obvious way to obtain the value (or the key) from a
> > dictionary that is known to hold only one item?
>
> v = d.popitem()[1]
>
> > More importantly, is there a good reason why we don't have d.pop() for
> > dictionaries?
>
> My guess is because it's not generally useful to get an arbitrary
> value from a dict without its corresponding key. Hence the existence
> of popitem().
>
> --
> Greg
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to