Behaviour of pop() for dictionaries

BlindAnagram blindanagram at nowhere.org
Mon Jun 14 17:18:17 EDT 2021


On 14/06/2021 20:43, Chris Angelico wrote:
> On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram <blindanagram at nowhere.org> 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.
>>
> 
> Is this actually important or are you just looking for a meaningless
> "inconsistency"? Dictionaries are fundamentally different from lists.
> Is it really that hard to use popitem?

No I am not looking for meaningless inconsistency - just the opposite in 
fact - meaningful consistency.

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.

No it isn't hard to use popitem() but it evidently proved hard for me to 
remember that it was there.

   Brian


More information about the Python-list mailing list