Re: Behaviour of pop() for dictionaries

2021-06-15 Thread dn via Python-list
On 15/06/2021 21.37, BlindAnagram wrote: > On 15/06/2021 00:11, dn wrote: >> On 15/06/2021 09.18, BlindAnagram wrote: >>> On 14/06/2021 20:43, Chris Angelico wrote: On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram >> ... > I think the difference here is that I know I am going to have to look at >

Re: Behaviour of pop() for dictionaries

2021-06-15 Thread BlindAnagram
On 15/06/2021 00:11, dn wrote: On 15/06/2021 09.18, BlindAnagram wrote: On 14/06/2021 20:43, Chris Angelico wrote: On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram ... No it isn't hard to use popitem() but it evidently proved hard for me to remember that it was there. If that's a problem, you'

Re: Behaviour of pop() for dictionaries

2021-06-15 Thread BlindAnagram
On 15/06/2021 01:36, Terry Reedy wrote: On 6/14/2021 5:18 PM, BlindAnagram wrote: I believe that consistency in how methods common to different types work is useful since it adds to the coherence of the language as a whole and avoids the need to remember special cases. Each collection class

Re: Behaviour of pop() for dictionaries

2021-06-15 Thread Cameron Simpson
On 14Jun2021 09:39, BlindAnagram wrote: >However, d.pop(key, [default]) returns the value (or the default) and >consistency with other pops (a good thing in my view) would suggest >that d.pop() could return a random value, which would serve my purpose >when there is only one element. If you do

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread Terry Reedy
On 6/14/2021 5:18 PM, BlindAnagram wrote: I believe that consistency in how methods common to different types work is useful since it adds to the coherence of the language as a whole and avoids the need to remember special cases. Each collection class *is* a special case, and pop has to be ad

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread dn via Python-list
On 15/06/2021 09.18, BlindAnagram wrote: > On 14/06/2021 20:43, Chris Angelico wrote: >> On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram ... > No it isn't hard to use popitem() but it evidently proved hard for me to > remember that it was there. If that's a problem, you're going to love using deques

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread BlindAnagram
On 14/06/2021 20:43, Chris Angelico wrote: On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram wrote: However, d.pop(key, [default]) returns the value (or the default) and consistency with other pops (a good thing in my view) would suggest that d.pop() could return a random value, which would serve my

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread Chris Angelico
On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram wrote: > However, d.pop(key, [default]) returns the value (or the default) and > consistency with other pops (a good thing in my view) would suggest that > d.pop() could return a random value, which would serve my purpose when > there is only one elemen

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread BlindAnagram
On 14/06/2021 08:29, Greg Ewing 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] Thanks, Greg, I missed that. More importantly, is there a good reason why

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread Stestagg
You can do the following: _,v = d.popitem() Or: key, value = d.popitem() Steve On Mon, 14 Jun 2021 at 20:10, Greg Ewing 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 ite

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread Greg Ewing
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