Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

A morsel of genuine history is a thing so rare as to be always valuable. -- Thomas Jefferson


devel / comp.lang.python / Re: Behaviour of pop() for dictionaries

SubjectAuthor
* Behaviour of pop() for dictionariesBlindAnagram
`* Re: Behaviour of pop() for dictionariesGreg Ewing
 +* Re: Behaviour of pop() for dictionariesBlindAnagram
 |+* Re: Behaviour of pop() for dictionariesChris Angelico
 ||`* Re: Behaviour of pop() for dictionariesBlindAnagram
 || +* Re: Behaviour of pop() for dictionariesdn
 || |`* Re: Behaviour of pop() for dictionariesBlindAnagram
 || | `- Re: Behaviour of pop() for dictionariesdn
 || `* Re: Behaviour of pop() for dictionariesTerry Reedy
 ||  `- Re: Behaviour of pop() for dictionariesBlindAnagram
 |`- Re: Behaviour of pop() for dictionariesCameron Simpson
 `- Re: Behaviour of pop() for dictionariesStestagg

1
Behaviour of pop() for dictionaries

<r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13636&group=comp.lang.python#13636

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!border2.nntp.ams1.giganews.com!nntp.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 13 Jun 2021 11:19:02 -0500
Newsgroups: comp.lang.python
X-Mozilla-News-Host: news://usenet.plus.net:119
From: blindana...@nowhere.org (BlindAnagram)
Subject: Behaviour of pop() for dictionaries
Date: Sun, 13 Jun 2021 17:19:02 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 7bit
Message-ID: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
Lines: 41
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-i0twgggcxQ/+3UT0WUt3sYqu7gIxXP7AP028/FyWOdjNlwIjQZOzsp2ApU58P/sIm2cj4R9KWXN5m3D!+xbMSb7eeySoegtfDTPtUm71mkqIKqAaOLttGMbqDWRIAE8bTAaCxRUwOptgWjPCzVf7+Njd88jm!VCQLRgksGLPS4ioOaPmW9SCHbg==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2253
 by: BlindAnagram - Sun, 13 Jun 2021 16:19 UTC

The pop() method exists for five mainstream data items and shows a range
of different behaviours for each of them.

But, of the five, pop for dictionaries is the only one for which the
first parameter is required and this makes d.pop() for dictionaries an
error rather than doing something useful.

I came across this in trying to use this sequence for a dictionary <d>:

if len(d.keys()) == 1:
v = d.pop()

I found it surprising that this failed given how the pops for the other
types work.

So I then tried:

v = d.values()[0]

and this doesn't work either since dict_keys items don't accept
indexing. So I was driven to use:

v = list(d.values())[0]

which seems to me a lot less intuitive (and messier) than d.pop().

These:

v = next(iter(d.values()))
v, = d.values()

also seem poor substitutes for giving d.pop() for dictionaries a useful
and intuitive purpose.

Am I missing the obvious way to obtain the value (or the key) from a
dictionary that is known to hold only one item?

More importantly, is there a good reason why we don't have d.pop() for
dictionaries?

Brian

Re: Behaviour of pop() for dictionaries

<iioeq6Fl58bU1@mid.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13640&group=comp.lang.python#13640

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ew...@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: Behaviour of pop() for dictionaries
Date: Mon, 14 Jun 2021 19:29:08 +1200
Lines: 15
Message-ID: <iioeq6Fl58bU1@mid.individual.net>
References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net Qv7W0+1ZqAeVoGjiBpsimwnF92KeTot52k8R2OuEwUGXf0Sxta
Cancel-Lock: sha1:0QiL5EtNZlMhTqtjSSSvkz+l1P0=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:78.0)
Gecko/20100101 Thunderbird/78.4.0
In-Reply-To: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
Content-Language: en-US
 by: Greg Ewing - Mon, 14 Jun 2021 07:29 UTC

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

Re: Behaviour of pop() for dictionaries

<fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13643&group=comp.lang.python#13643

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!border2.nntp.ams1.giganews.com!nntp.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 14 Jun 2021 03:39:25 -0500
Subject: Re: Behaviour of pop() for dictionaries
Newsgroups: comp.lang.python
References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
From: blindana...@nowhere.org (BlindAnagram)
Date: Mon, 14 Jun 2021 09:39:26 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
MIME-Version: 1.0
In-Reply-To: <iioeq6Fl58bU1@mid.individual.net>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 7bit
Message-ID: <fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
Lines: 22
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-9dY/wcB6XN2H8NDBTkNRkqLOAvOdVfjJ1ahOV5i9k7qM0txGqg1E9FmZi2VDg4XBEWA5p7nCysF9yTX!xiZgzR76DleeqQC0h1zHA1rvbsH7rKfVM1cTPuDA/L5rTRR8Oloqe7maYXrqjQNlRx6NoL1p6LGz!OX2vSyLFjHUFovuNc4l99jGPWA==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2006
 by: BlindAnagram - Mon, 14 Jun 2021 08:39 UTC

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 we don't have d.pop() for
>> dictionaries?
>
> My guess is because it's not generally useful to get an returns the value arbitrary
> value from a dict without its corresponding key. Hence the existence
> of popitem().

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.

Re: Behaviour of pop() for dictionaries

<mailman.34.1623698051.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13652&group=comp.lang.python#13652

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: stest...@gmail.com (Stestagg)
Newsgroups: comp.lang.python
Subject: Re: Behaviour of pop() for dictionaries
Date: Mon, 14 Jun 2021 20:13:57 +0100
Lines: 31
Message-ID: <mailman.34.1623698051.4164.python-list@python.org>
References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
<CACFDE8byv=--5MNW6RDmnAFtUmLE9aqf2hhB+_j5LEzdj=h58w@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de r+FpgXilRywCQ0gpfN/9fAG2sdEziPkzDh6LFDOHsF3A==
Return-Path: <stestagg@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=uvqyxwdV;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'url:mailman': 0.09;
'cc:addr:python-list': 0.09; 'subject:Behaviour': 0.09;
'subject:pop': 0.09; 'cc:no real name:2**0': 0.13; '&gt;': 0.14;
'arbitrary': 0.16; 'blindanagram': 0.16; 'dict': 0.16;
'existence': 0.16; 'greg': 0.16; 'key,': 0.16; 'key.': 0.16;
'received:209.85.215': 0.16; 'received:209.85.215.171': 0.16;
'received:mail-pg1-f171.google.com': 0.16; 'subject:() ': 0.16;
'subject:dictionaries': 0.16; 'wrote:': 0.16; 'url:listinfo':
0.16; 'cc:addr:python.org': 0.19; 'url-ip:188.166.95.178/32':
0.20; 'url-ip:188.166.95/24': 0.20; 'url-ip:188.166/16': 0.23;
'cc:2**0': 0.27; 'jun': 0.27; 'url-ip:188/8': 0.29; 'there': 0.31;
'am,': 0.31; 'guess': 0.32; 'obtain': 0.32; 'message-
id:@mail.gmail.com': 0.33; 'header:In-Reply-To:1': 0.33;
'subject:for': 0.33; 'hold': 0.34; 'received:google.com': 0.34;
'missing': 0.35; 'from:addr:gmail.com': 0.35; 'way': 0.37; '(or':
0.37; 'received:209.85': 0.38; "it's": 0.38; 'received:209': 0.38;
'reason': 0.40; 'generally': 0.61; 'obvious': 0.69; 'known': 0.75;
'2021': 0.84; 'importantly,': 0.84; 'item?': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=T782AutSZ7BoJvjIam+vmS1gWoD8harmejlMOxoCQmM=;
b=uvqyxwdV7nm9OyCTkWUJkXsJPktJBdeRsNSABIuTZxgZf5OZ5FPIbUipQqP0Z/Y1V8
14BdYg14gsrbYOvHBWsp1sa4A8KccdPhtCyu7qWnjmwTHj20CBjEL+GSGgst7v/NDTBg
PJmFHvJ9G2UujdfTM8xl0jLim74JKIsAaAmUWisV4JF6FN1yta2TEG26SH1AFZDIy8GV
4QSTxVrVm5Y3eEyiVOimXoNOEo0/nBqkFU52llAAosyJxG3M++17eaWVQPHEr777YxUi
4aNwnwHt7N2Tc0OU2XCJ8fQSGH0i1/oiehZqtcnnPjToxXomtqa78VWXFJCBus0kx/g4
bQug==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=T782AutSZ7BoJvjIam+vmS1gWoD8harmejlMOxoCQmM=;
b=r0OOEbdxzPIZ9GSMn1mzMRZ1iXDGrL1ftVHXDqHU41ZzEsSVk8nIZKtP/fVGD3YPdX
p31C3SvyodKTrYl2LYeg0cNlmQbO2Fv9OI6c4lNFYI+A+JenYIBJVq/10njovdPHhzoG
/VKpvQf3r0ZWJCFsQ5k9AXiUT/Z7HJfa1SQ7Dp6hnFT6xpGegN/fZXGhcjCW8767qtns
Nk32+ClY/pKb0evIhQvtiz00RBeiPp9VYO46QYErlCx7VV7XKJ7xNUt5T4fTBDgUS76U
DaB7QzpFOVihdSYQzKSwLr7O+PSdtwTaE9nHebeDSiB0GEz9RKurhQ+RGR9d3q+6fkCK
RXrg==
X-Gm-Message-State: AOAM533Xle4Cs9vH2AuF3nHcHo4LwRP328g05bWbTYuRLjVpBLHYYL5m
nLSFZxEmdJ6XBKxbgkgkrWVoxz8cWqHaqJ9TcLRw8oUv
X-Google-Smtp-Source: ABdhPJxlnwfaMTL2nqawJ4Kxyr99jfDJf9ZpUY7SuwOLPFvvzJDy6RCSSS/QpRyhY+lznW+c1HrNwXooxLTyXT47U7s=
X-Received: by 2002:a63:5b0e:: with SMTP id p14mr18260518pgb.110.1623698048706;
Mon, 14 Jun 2021 12:14:08 -0700 (PDT)
In-Reply-To: <iioeq6Fl58bU1@mid.individual.net>
X-Content-Filtered-By: Mailman/MimeDel 2.1.34
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CACFDE8byv=--5MNW6RDmnAFtUmLE9aqf2hhB+_j5LEzdj=h58w@mail.gmail.com>
X-Mailman-Original-References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
 by: Stestagg - Mon, 14 Jun 2021 19:13 UTC

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.ewing@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
>

Re: Behaviour of pop() for dictionaries

<mailman.37.1623699830.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13655&group=comp.lang.python#13655

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Behaviour of pop() for dictionaries
Date: Tue, 15 Jun 2021 05:43:37 +1000
Lines: 12
Message-ID: <mailman.37.1623699830.4164.python-list@python.org>
References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
<fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
<CAPTjJmpfgiQB=dx8H4iiutBjzEQqZAM8CxuNLHLy9B2GAVK+wg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de h12gLtQHFHMB9Q1YDmYG5wpZcyjOfpFvYCVBmRLOo9Jg==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=TcxKM08h;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'random': 0.05;
'consistency': 0.09; 'subject:Behaviour': 0.09; 'subject:pop':
0.09; 'blindanagram': 0.16; 'chrisa': 0.16; 'from:addr:rosuav':
0.16; 'from:name:chris angelico': 0.16; 'subject:() ': 0.16;
'subject:dictionaries': 0.16; 'wrote:': 0.16; 'tue,': 0.18;
'returns': 0.23; 'to:addr:python-list': 0.23; 'suggest': 0.25;
'purpose': 0.26; 'jun': 0.27; 'there': 0.31; 'to:name:python':
0.32; 'message-id:@mail.gmail.com': 0.33; 'received:209.85.166':
0.33; 'header:In-Reply-To:1': 0.33; 'subject:for': 0.33;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35; '(or':
0.37; 'really': 0.37; 'received:209.85': 0.38; 'hard': 0.38;
'received:209': 0.38; 'use': 0.38; 'could': 0.40; '2021': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=vknfwz3QfqAdc6EUxnN9y3Hine8dIctaXhr16ytbgdc=;
b=TcxKM08h9YyVmOryx2Puw81zsHmf+nRkuNemHsFjuAWnbVLSx/njIhyFLmWhGEQhJC
AS6x4KiNqpZwDEufJau5/uvXiLOvkt3osBKEqT/T4LqD1cfZ5H/QBtxnaH/9D5NFHuK+
+mAVAKy1FHiK+EpbJy+60ASvEeIZof+q6vyb3x6EA1x4hARCZ5xHFS5F29pm1NwcVjVa
wqQ/iWyI5OkuLnQXTFnBrbMj3NNmyYKydfu/Wpk2GOJWIlFko3wVXDglcdi5GLSbNx0f
RJiWpcQIH0IWv1jEeoeQ6LVVqgG+71VN89PGivKHWoseM3ClRlamcdk8CBVRIvQe2Dpl
7hQg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=vknfwz3QfqAdc6EUxnN9y3Hine8dIctaXhr16ytbgdc=;
b=bj+JN4Xj0RiEL5k4yRyOyLl/UakUqlnADGIRh8PwZhqsv1KOOBCSyW+zgR9H/8xQWy
822yB2RGSlc2u0LLWF4Na1ahpaxjOvkzbCE1oIwAqZEd+JhO52VWKOkW381X1413ipnl
8z2vlXC3kCRmfF4Uk3N70qIYru2XgJHXzlBEFPO/YVHoC6QXRaOwyxYduYYYPO/rmtwL
Mx/82Zr/DkkOSHtfV6UyEfXM65QnVyEfuFkF/mOxvJEPLR2+cOzVGWph1VD9EfxpgMm1
Sn5ytIxgjOcl8on/PzeadTYCyaz+2dX+PTR5II+WSKE2Ffq4SR2HYZ2JyOurJRTA80ET
FQAw==
X-Gm-Message-State: AOAM530p5N1jTFcurafVEql1+7ZyoZjDFTZXcuFWAGZQN0refNLlHoXY
fQizjQ3RUP7F2J98PH2mjoy4SV9qhADQFxOmkxN2akXj
X-Google-Smtp-Source: ABdhPJyoEuNhW9T9AQbBF2XmCfxnk37NxbAYL8oKyD2+cz5VXYLwhBMXAWw0e+7SaiaFW6zZUT7w9Exe1f2KD0iuo8Q=
X-Received: by 2002:a92:cf0a:: with SMTP id c10mr15241235ilo.97.1623699827990;
Mon, 14 Jun 2021 12:43:47 -0700 (PDT)
In-Reply-To: <fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmpfgiQB=dx8H4iiutBjzEQqZAM8CxuNLHLy9B2GAVK+wg@mail.gmail.com>
X-Mailman-Original-References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
<fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
 by: Chris Angelico - Mon, 14 Jun 2021 19:43 UTC

On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram <blindanagram@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?

ChrisA

Re: Behaviour of pop() for dictionaries

<0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13661&group=comp.lang.python#13661

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!border2.nntp.ams1.giganews.com!nntp.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 14 Jun 2021 16:18:14 -0500
Subject: Re: Behaviour of pop() for dictionaries
Newsgroups: comp.lang.python
References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
<fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
<CAPTjJmpfgiQB=dx8H4iiutBjzEQqZAM8CxuNLHLy9B2GAVK+wg@mail.gmail.com>
<mailman.37.1623699830.4164.python-list@python.org>
From: blindana...@nowhere.org (BlindAnagram)
Date: Mon, 14 Jun 2021 22:18:17 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
MIME-Version: 1.0
In-Reply-To: <mailman.37.1623699830.4164.python-list@python.org>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 7bit
Message-ID: <0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk>
Lines: 23
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-xTw48tDWIe0Eed+KpNHdU+xRvAc6mVrzquQ6RNSt4tJOnIQFARpZwAgrWZJpIFMQlhkyhMDVLZPv4z3!oJIDfAyEQ9To+UGEPcycOx56+ERyJp9rDouI+w2i3pYcYvHVT15r/5iYK5nxdlIkOTO+ZFjdBoLu!gJ6xVN9LYrn4y0UIIgYSlM3pKA==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2402
 by: BlindAnagram - Mon, 14 Jun 2021 21:18 UTC

On 14/06/2021 20:43, Chris Angelico wrote:
> On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram <blindanagram@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

Re: Behaviour of pop() for dictionaries

<mailman.43.1623712309.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13664&group=comp.lang.python#13664

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonL...@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Behaviour of pop() for dictionaries
Date: Tue, 15 Jun 2021 11:11:31 +1200
Organization: DWM
Lines: 85
Message-ID: <mailman.43.1623712309.4164.python-list@python.org>
References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
<fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
<CAPTjJmpfgiQB=dx8H4iiutBjzEQqZAM8CxuNLHLy9B2GAVK+wg@mail.gmail.com>
<mailman.37.1623699830.4164.python-list@python.org>
<0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk>
<0184de41-3482-c576-60ed-343fbe0fe73d@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 6x5JNLykFdnIEeLrKBkWpAypEjkWr7eAGV9E1/1quDdw==
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=VYMJX91t; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; "python's": 0.05; 'queue':
0.07; 'underlying': 0.07; '=dn': 0.09; 'angelico': 0.09;
'consistency': 0.09; 'fact,': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'python)': 0.09; 'received:192.168.1.64': 0.09; 'studying':
0.09; 'subject:Behaviour': 0.09; 'subject:pop': 0.09;
'theoretical': 0.09; 'theory': 0.09; '(python)': 0.16;
'arguments': 0.16; 'blindanagram': 0.16; 'collection.': 0.16;
'confusion': 0.16; 'dict': 0.16; 'exhibits': 0.16; 'inherently':
0.16; 'key-value': 0.16; 'message-id:@DancesWithMice.info': 0.16;
'queues': 0.16; 'recall': 0.16; 'received:51.254': 0.16;
'received:51.254.211': 0.16; 'received:51.254.211.219': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16; 'shuffling':
0.16; 'somewhat': 0.16; 'stacks': 0.16; 'strings,': 0.16;
'structures': 0.16; 'subject:() ': 0.16; 'subject:dictionaries':
0.16; 'tuples,': 0.16; 'whilst': 0.16; 'wrote:': 0.16; 'python':
0.16; 'tue,': 0.18; 'programming': 0.21; 'languages': 0.23;
'behavior': 0.23; 'problem,': 0.23; 'purposes': 0.23; 'ran': 0.23;
'returns': 0.23; 'to:addr:python-list': 0.23; 'student': 0.24;
'idea': 0.25; 'chris': 0.26; 'brought': 0.27; 'concept': 0.27;
'elements': 0.27; 'jun': 0.27; 'studies': 0.27; 'effect': 0.28;
'module': 0.28; "isn't": 0.29; 'coming': 0.29; '(and': 0.30;
'header:User-Agent:1': 0.31; 'header:Organization:1': 0.31;
'received:192.168.1': 0.31; 'there': 0.31; 'but': 0.31; 'item':
0.31; 'research.': 0.32; 'said,': 0.32; 'using': 0.33; 'header:In-
Reply-To:1': 0.33; 'subject:for': 0.33; 'same': 0.34;
'necessarily': 0.35; 'level.': 0.35; 'trying': 0.36; 'also,':
0.36; 'received:192.168': 0.37; "that's": 0.37; '(or': 0.37;
'hard': 0.38; 'those': 0.38; "it's": 0.38; 'something': 0.38;
'going': 0.38; 'use': 0.38; 'list': 0.39; 'taking': 0.40;
'whether': 0.40; 'enough': 0.40; "skip:' 10": 0.40; 'skip:q 10':
0.40; 'well.': 0.61; 'love': 0.61; 'remember': 0.61; 'upon': 0.63;
'types': 0.63; 'ever': 0.63; 'key': 0.63; 'received:userid': 0.64;
'reserve': 0.65; 'thus': 0.65; 'skip:t 20': 0.67; 'great': 0.67;
'order': 0.68; 'time,': 0.69; 'etc,': 0.69; 'factor': 0.69;
'latter': 0.69; 'refers': 0.69; 'surprise': 0.69; 'took': 0.70;
'deliver': 0.71; 'terms': 0.72; 'operations': 0.74; 'known': 0.75;
'received:51': 0.77; '....': 0.81; '2021': 0.84; "'the": 0.84;
'entered': 0.84; 'implies': 0.84; 'inconsistent': 0.84; 'proved':
0.84; 'stack,': 0.84; 'thus,': 0.84; 'opposite': 0.91;
'dependent': 0.93; 'implied': 0.93
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on vps517507.ovh.net
X-Spam-Level:
X-Spam-Status: No, score=-3.0 required=5.0 tests=ALL_TRUSTED,BAYES_00,
DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,NICE_REPLY_A autolearn=ham
autolearn_force=no version=3.4.0
DKIM-Filter: OpenDKIM Filter v2.11.0 mail.rangi.cloud 8AF3852D0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1623712306;
bh=V5/G34yv1aNexpSBDH2/2+VNB4sOK4RdWBDHBnBkFxk=;
h=Subject:To:References:From:Date:In-Reply-To:From;
b=VYMJX91tx2dLq1+ZUgA9FJvNwmXV/mcRMX68tuvkpd9vO9oJbmQ/3mHSSBLXQez9s
0jCcDFzLpsrUg7yJ7TLwAP/qeRafz27w4SFLtLgdxHBcvi9dFEZfgD90fmw6R1zV3G
BYrQMBUUZnNiGskjEBOOu5G+W0vndkw45ZNf/v29TOdPfOqDEtBA/YVRj+KZWgehmu
4NUd1vmYqIZkRGJGidvclpLK3HLW09uGT23GawYTipqhKGdUXZpM4h2Y53lQAh60QB
eZRd0eiythJg3uPa4J20F+wT0L8e7Lx/2aiAd09ReVjo9Mwx2JNZvwyaRQWr1LwcqB
144ZokMd9c2IQ==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
In-Reply-To: <0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk>
Content-Language: en-GB
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <0184de41-3482-c576-60ed-343fbe0fe73d@DancesWithMice.info>
X-Mailman-Original-References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
<fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
<CAPTjJmpfgiQB=dx8H4iiutBjzEQqZAM8CxuNLHLy9B2GAVK+wg@mail.gmail.com>
<mailman.37.1623699830.4164.python-list@python.org>
<0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk>
 by: dn - Mon, 14 Jun 2021 23:11 UTC

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 with their
'popping from the left' and 'popping from the right' concepts!

I don't know if you are ComSc student or not, but there isn't even
consistency at the theoretical level. I first arrived at the concept of
"queuing" and "dequeuing" (NB the latter is not the same as the Python
Collections module "deque" library) whilst studying Queue Theory in
Operations Research. At about the same time, my ComSc studies took me
into "stacks".

Queues are known as FIFO constructs - "first-in, first-out".
Stacks are somewhat the opposite: LIFO - "last-in, first-out".

The "pop" operation was defined as taking the "next" item from the queue
or the "last" item from a stack (the opposite of "push"). However,
between queue and stack, the term "next" refers to opposite ends of the
(implementing in Python) list!

In fact, coming from a Burroughs mainframe, which ran on "stack
architecture" (cf IBM's multiplicity of "ALU registers"), it came as
something of a surprise when programming languages started allowing me
to "pop" elements that weren't at the LIFO-end of the 'list', eg
list.pop( 3 ) where len( list ) > 4!

Next consider how the terms "next" and "element" factor into the
thinking. If we consider a (Python) list there is an implied sequence of
elements based upon their relative position. Notice also that the basic
implementation of list.pop() is LIFO! Whereas, the definition of a set
involves no concept of sequence or order - only of membership (and that
the elements are "hashable"). Accordingly, a pop() operation returns an
"arbitrary value", cf 'next please'.

Similarly, a dict's keys are referred-to as hashable, with the idea of
"random access" to an element via its key (cf the "sequential access" of
a list). Thus, we can ask to pop() a dict, but only if we provide a key
- in which case, pop( key ) is the same as dict[ key ] except that the
key-value pair is also removed from the dict!

Recall though, it is possible to use list.pop() without any argument.
So, consistency has been thrown-out-the-window there as well.

Also, with LIFO in-mind, Python v3.7 brought a concept of 'sequence'
(population order) to dicts, and thus we now have this "guarantee" in
popitem() - and thus a memory-confusion for those of us who learned the
original "arbitrary" definition - confusion both of dict behavior and of
dict.popitem() specifically!

Worse confusion awaits (and referring to a conversation 'here' last
week) Python's pop() exhibits elements of both an "expression" and of a
"statement", ie it not only returns a value, but it affects
(?"side-effects") the underlying collection. Thus, no pop() for strings,
tuples, etc, because they are immutable collections!

The action of pop() is clearly inconsistent across types of collection.
It's effect is data-structure dependent because the purposes of those
structures are inherently different. "Consistency" would aid memory, but
"polymorphism" can only deliver functionality according to the
characteristics of the specific data-type!

Having entered the queue-of-life a long time ago, and shuffling ever
closer to 'the end of the line', this memory-challenged 'silver-surfer'
prefers to reserve pop() for straightforward stacks and lists, which
implies quite enough inconsistency, without trying to convolute my mind
to pop()-ing dicts, sets (or 'worse'!).

That said, whether I actually use dict.pop() or not, these 'features'
which are consistent in name but not necessarily in arguments or
effects, contribute to Python's great flexibility and power! Thank
goodness for help() and the Python docs...
--
Regards,
=dn

Re: Behaviour of pop() for dictionaries

<mailman.47.1623718113.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13669&group=comp.lang.python#13669

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: tjre...@udel.edu (Terry Reedy)
Newsgroups: comp.lang.python
Subject: Re: Behaviour of pop() for dictionaries
Date: Mon, 14 Jun 2021 20:36:49 -0400
Lines: 31
Message-ID: <mailman.47.1623718113.4164.python-list@python.org>
References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
<fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
<CAPTjJmpfgiQB=dx8H4iiutBjzEQqZAM8CxuNLHLy9B2GAVK+wg@mail.gmail.com>
<mailman.37.1623699830.4164.python-list@python.org>
<0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk>
<sa8sn3$953$1@ciao.gmane.io>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de zBSxJzT1CxUhlKfnSAashw7b8MD1pTqLTCwnPHPl+ZYg==
Return-Path: <python-python-list@m.gmane-mx.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'random': 0.05; 'guido':
0.07; 'cases.': 0.09; 'consistency': 0.09; 'depend': 0.09;
'fact,': 0.09; 'message-id:@ciao.gmane.io': 0.09;
'received:ciao.gmane.io': 0.09; 'received:gmane.io': 0.09;
'received:list': 0.09; 'subject:Behaviour': 0.09; 'subject:pop':
0.09; 'terry': 0.09; '(unless': 0.16; '(when': 0.16;
'blindanagram': 0.16; 'default.': 0.16; 'dicts': 0.16;
'from:addr:udel.edu': 0.16; 'item,': 0.16; 'missed': 0.16;
'received:116.202': 0.16; 'received:116.202.254': 0.16;
'received:116.202.254.214': 0.16; 'removes': 0.16; 'sets,': 0.16;
'stack.': 0.16; 'subject:() ': 0.16; 'subject:dictionaries': 0.16;
'wrote:': 0.16; 'api': 0.18; 'pm,': 0.20; 'language': 0.22;
'returns': 0.23; 'to:addr:python-list': 0.23; 'default': 0.28;
'error': 0.28; 'header:User-Agent:1': 0.31; 'seem': 0.31; 'but':
0.31; 'item': 0.31; 'class': 0.33; 'header:In-Reply-To:1': 0.33;
'subject:for': 0.33; 'lists': 0.37; 'special': 0.37; 'list': 0.39;
'could': 0.40; 'common': 0.60; 'generally': 0.61; 'remember':
0.61; 'types': 0.63; 'essential': 0.65; 'bad': 0.68; 'addition':
0.68; 'that,': 0.68; 'time,': 0.69; 'adds': 0.69; 'received:116':
0.71; 'added.': 0.84; 'pop': 0.91; 'sub': 0.91
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
In-Reply-To: <0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk>
Content-Language: en-US
X-Mailman-Approved-At: Mon, 14 Jun 2021 20:48:32 -0400
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <sa8sn3$953$1@ciao.gmane.io>
X-Mailman-Original-References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
<fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
<CAPTjJmpfgiQB=dx8H4iiutBjzEQqZAM8CxuNLHLy9B2GAVK+wg@mail.gmail.com>
<mailman.37.1623699830.4164.python-list@python.org>
<0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk>
 by: Terry Reedy - Tue, 15 Jun 2021 00:36 UTC

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 adjusted to
each. However, you seem to have missed an essential commonality.

Lists and dicts are both subscripted classes. So the basic API is
col.pop(sub), which removes and returns the sub item, whereas col[sub]
leaves and returns.

Lists have a special index, -1, the most commonly used, so that is the
default. In fact, when I proposed list.pop(), I only proposed that, as
I wanted pop to be the inverse of append, so a list could be used as a
stack.

Bad list subscripts are an error (unless one is slicing), whereas where
dicts allow a default (when subscripted with the get method). Hence the
optional default only for dicts.

At one time, dicts, like sets, were unordered collections (of functional
item pairs). dict.pop(), with no arg, could have been used to return a
random 2-ple, but Guido is generally against having return types depend
on arguments. So a new popxxx name was added. Note that deques have a
popleft in addition to pop (right).

--
Terry Jan Reedy

Re: Behaviour of pop() for dictionaries

<mailman.54.1623745133.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13683&group=comp.lang.python#13683

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: cs...@cskk.id.au (Cameron Simpson)
Newsgroups: comp.lang.python
Subject: Re: Behaviour of pop() for dictionaries
Date: Tue, 15 Jun 2021 18:18:48 +1000
Lines: 13
Message-ID: <mailman.54.1623745133.4164.python-list@python.org>
References: <fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
<YMhiaG/FJNRmbxHD@cskk.homeip.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news.uni-berlin.de T6TKv49S3+LSEd1xuj/a6Qe7YNgwP2fnhxcQB9mtcQ8w==
Return-Path: <cameron@cskk.id.au>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'random': 0.05;
'subject:Behaviour': 0.09; 'subject:pop': 0.09; 'cheers,': 0.10;
'blindanagram': 0.16; 'cameron': 0.16; 'from:addr:cs': 0.16;
'from:addr:cskk.id.au': 0.16; 'from:name:cameron simpson': 0.16;
'message-id:@cskk.homeip.net': 0.16; 'received:13.237': 0.16;
'received:13.237.201': 0.16; 'received:13.237.201.189': 0.16;
'received:cskk.id.au': 0.16; 'received:id.au': 0.16;
'received:mail.cskk.id.au': 0.16; 'simpson': 0.16; 'subject:() ':
0.16; 'subject:dictionaries': 0.16; 'wrote:': 0.16; 'maybe': 0.20;
'returns': 0.23; 'to:addr:python-list': 0.23; 'suggest': 0.25;
'purpose': 0.26; 'header:User-Agent:1': 0.31; 'there': 0.31;
'received:au': 0.31; 'header:In-Reply-To:1': 0.33; 'subject:for':
0.33; '(or': 0.37; 'could': 0.40; 'key': 0.63; 'received:userid':
0.64; 'received:13': 0.65; 'care': 0.67
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
User-Agent: Mutt/2.0.3 (2020-12-04)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <YMhiaG/FJNRmbxHD@cskk.homeip.net>
X-Mailman-Original-References: <fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
 by: Cameron Simpson - Tue, 15 Jun 2021 08:18 UTC

On 14Jun2021 09:39, BlindAnagram <blindanagram@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.

If you don't care what key was popped, maybe you want a set and not a
dict?

Just a thought.

Cheers,
Cameron Simpson <cs@cskk.id.au>

Re: Behaviour of pop() for dictionaries

<LrGdnYY_vvki6VX9nZ2dnUU78cnNnZ2d@brightview.co.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13686&group=comp.lang.python#13686

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!feeder1.feed.usenet.farm!feed.usenet.farm!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 15 Jun 2021 04:37:03 -0500
Subject: Re: Behaviour of pop() for dictionaries
Newsgroups: comp.lang.python
References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
<fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
<CAPTjJmpfgiQB=dx8H4iiutBjzEQqZAM8CxuNLHLy9B2GAVK+wg@mail.gmail.com>
<mailman.37.1623699830.4164.python-list@python.org>
<0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk>
<0184de41-3482-c576-60ed-343fbe0fe73d@DancesWithMice.info>
<mailman.43.1623712309.4164.python-list@python.org>
From: blindana...@nowhere.org (BlindAnagram)
Date: Tue, 15 Jun 2021 10:37:03 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
MIME-Version: 1.0
In-Reply-To: <mailman.43.1623712309.4164.python-list@python.org>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 7bit
Message-ID: <LrGdnYY_vvki6VX9nZ2dnUU78cnNnZ2d@brightview.co.uk>
Lines: 93
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-Jdj73zXA9UW7ez8RtvO7TZyG+MkH9l+xM01L4Q7r67PggIFvenogqg+Jt/J21vVEIGz8tMzA1190foi!h5QSIPiGFCuEj4s41HNe/mUZmWeyyI+RRPcL3qTTxw97qTavkT3bbaK45w69xaZcOJE3b4brfU9e!WHQVvHBSODGrnU7rkxiw8e7D2Q==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 6244
 by: BlindAnagram - Tue, 15 Jun 2021 09:37 UTC

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 going to love using deques with their
> 'popping from the left' and 'popping from the right' concepts!

I think the difference here is that I know I am going to have to look at
the documentation for dequeue when I want to use it. For lists, sets and
dictionaries, I don't expect to look at the documentation and pop()
seemed a good bet for what I wanted to do.

> I don't know if you are ComSc student or not, but there isn't even
> consistency at the theoretical level. I first arrived at the concept of
> "queuing" and "dequeuing" (NB the latter is not the same as the Python
> Collections module "deque" library) whilst studying Queue Theory in
> Operations Research. At about the same time, my ComSc studies took me
> into "stacks".

My student days are well over (about 60 years over).

> Queues are known as FIFO constructs - "first-in, first-out".
> Stacks are somewhat the opposite: LIFO - "last-in, first-out".
>
> The "pop" operation was defined as taking the "next" item from the queue
> or the "last" item from a stack (the opposite of "push"). However,
> between queue and stack, the term "next" refers to opposite ends of the
> (implementing in Python) list!
>
> In fact, coming from a Burroughs mainframe, which ran on "stack
> architecture" (cf IBM's multiplicity of "ALU registers"), it came as
> something of a surprise when programming languages started allowing me
> to "pop" elements that weren't at the LIFO-end of the 'list', eg
> list.pop( 3 ) where len( list ) > 4!
>
>
> Next consider how the terms "next" and "element" factor into the
> thinking. If we consider a (Python) list there is an implied sequence of
> elements based upon their relative position. Notice also that the basic
> implementation of list.pop() is LIFO! Whereas, the definition of a set
> involves no concept of sequence or order - only of membership (and that
> the elements are "hashable"). Accordingly, a pop() operation returns an
> "arbitrary value", cf 'next please'.
>
> Similarly, a dict's keys are referred-to as hashable, with the idea of
> "random access" to an element via its key (cf the "sequential access" of
> a list). Thus, we can ask to pop() a dict, but only if we provide a key
> - in which case, pop( key ) is the same as dict[ key ] except that the
> key-value pair is also removed from the dict!
>
> Recall though, it is possible to use list.pop() without any argument.
> So, consistency has been thrown-out-the-window there as well.
>
> Also, with LIFO in-mind, Python v3.7 brought a concept of 'sequence'
> (population order) to dicts, and thus we now have this "guarantee" in
> popitem() - and thus a memory-confusion for those of us who learned the
> original "arbitrary" definition - confusion both of dict behavior and of
> dict.popitem() specifically!
>
> Worse confusion awaits (and referring to a conversation 'here' last
> week) Python's pop() exhibits elements of both an "expression" and of a
> "statement", ie it not only returns a value, but it affects
> (?"side-effects") the underlying collection. Thus, no pop() for strings,
> tuples, etc, because they are immutable collections!
>
> The action of pop() is clearly inconsistent across types of collection.
> It's effect is data-structure dependent because the purposes of those
> structures are inherently different. "Consistency" would aid memory, but
> "polymorphism" can only deliver functionality according to the
> characteristics of the specific data-type!

Yes, but we can still seek consistency where it is possible

> Having entered the queue-of-life a long time ago, and shuffling ever
> closer to 'the end of the line', this memory-challenged 'silver-surfer'
> prefers to reserve pop() for straightforward stacks and lists, which
> implies quite enough inconsistency, without trying to convolute my mind
> to pop()-ing dicts, sets (or 'worse'!).
>
> That said, whether I actually use dict.pop() or not, these 'features'
> which are consistent in name but not necessarily in arguments or
> effects, contribute to Python's great flexibility and power! Thank
> goodness for help() and the Python docs...

I don't like 'pop's at all since it meant that a valve had exploded on
the Ferranti Pegasus that was my first encounter with computers.

Brian

Re: Behaviour of pop() for dictionaries

<O-WdnVi-Fvgh6lX9nZ2dnUU78RvNnZ2d@brightview.co.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13688&group=comp.lang.python#13688

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!feeder1.feed.usenet.farm!feed.usenet.farm!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 15 Jun 2021 04:49:48 -0500
Subject: Re: Behaviour of pop() for dictionaries
Newsgroups: comp.lang.python
References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
<fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
<CAPTjJmpfgiQB=dx8H4iiutBjzEQqZAM8CxuNLHLy9B2GAVK+wg@mail.gmail.com>
<mailman.37.1623699830.4164.python-list@python.org>
<0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk>
<sa8sn3$953$1@ciao.gmane.io>
<mailman.47.1623718113.4164.python-list@python.org>
From: blindana...@nowhere.org (BlindAnagram)
Date: Tue, 15 Jun 2021 10:49:49 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
MIME-Version: 1.0
In-Reply-To: <mailman.47.1623718113.4164.python-list@python.org>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 8bit
Message-ID: <O-WdnVi-Fvgh6lX9nZ2dnUU78RvNnZ2d@brightview.co.uk>
Lines: 39
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-S6e41c0f6eK/1B7taEARQ4M5VTe0HD90uf2wwebgYx3cKekrj2odPYqXwOcFucQhSMBZHvNBCqKar7W!OIJSP2gvE/SOei9+N/Xygi3dBhP2ETeteEqGFfJl8qWdfZROYZTWQEqkywvR24zwuZR0JkksKR+2!eReP+VgAndhUKUJoGsT5ZKKrqg==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 3328
 by: BlindAnagram - Tue, 15 Jun 2021 09:49 UTC

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 *is* a special case, and pop has to be adjusted to
> each.  However, you seem to have missed an essential commonality.
>
> Lists and dicts are both subscripted classes.  So the basic API is
> col.pop(sub), which removes and returns the sub item, whereas col[sub]
> leaves and returns.
>
> Lists have a special index, -1, the most commonly used, so that is the
> default.  In fact, when I proposed list.pop(), I only proposed that, as
> I wanted pop to be the inverse of append, so a list could be used as a
> stack.
>
> Bad list subscripts are an error (unless one is slicing), whereas where
> dicts allow a default (when subscripted with the get method).  Hence the
> optional default only for dicts.
>
> At one time, dicts, like sets, were unordered collections (of functional
> item pairs). dict.pop(), with no arg, could have been used to return a
> random 2-ple, but Guido is generally against having return types depend
> on arguments. So a new popxxx name was added.  Note that deques have a
> popleft in addition to pop (right).

Thanks for the interesting history.

Having found that dict.pop() caused an error, I did wonder whether it
should have returned a (key, value) pair but quickly came to the
conclusion that this would be awful because it would be inconsistent
with the normal value returned by pop(x). Sadly this did not result in
any recollection that there was a popitem() :-(

Brian

Re: Behaviour of pop() for dictionaries

<mailman.72.1623819959.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13713&group=comp.lang.python#13713

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonL...@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Behaviour of pop() for dictionaries
Date: Wed, 16 Jun 2021 17:04:29 +1200
Organization: DWM
Lines: 112
Message-ID: <mailman.72.1623819959.4164.python-list@python.org>
References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
<fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
<CAPTjJmpfgiQB=dx8H4iiutBjzEQqZAM8CxuNLHLy9B2GAVK+wg@mail.gmail.com>
<mailman.37.1623699830.4164.python-list@python.org>
<0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk>
<0184de41-3482-c576-60ed-343fbe0fe73d@DancesWithMice.info>
<mailman.43.1623712309.4164.python-list@python.org>
<LrGdnYY_vvki6VX9nZ2dnUU78cnNnZ2d@brightview.co.uk>
<12ae29a6-d96a-7075-6554-29e741aa5f73@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de wtzCMDdKRfPu6qRMrjIzMwE6EsocR6eDgITVZWeFUrfQ==
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=XCA80ibb; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; "python's": 0.05;
'ourselves': 0.07; 'queue': 0.07; 'python.': 0.07; '=dn': 0.09;
'angelico': 0.09; 'apparently': 0.09; 'consistency': 0.09;
'father': 0.09; 'from:addr:danceswithmice.info': 0.09;
'from:addr:pythonlist': 0.09; 'it)': 0.09; 'meant': 0.09;
'something,': 0.09; 'studying': 0.09; 'subject:Behaviour': 0.09;
'subject:pop': 0.09; 'theoretical': 0.09; 'theory': 0.09; '"what':
0.16; '(about': 0.16; '(full': 0.16; '>>>>': 0.16; 'ago)': 0.16;
'amazed': 0.16; 'arguments': 0.16; 'babbage': 0.16;
'blindanagram': 0.16; 'computers': 0.16; 'computers.': 0.16;
'contrary': 0.16; 'dict': 0.16; 'dimensions': 0.16; 'encounter':
0.16; 'exploded': 0.16; 'genetic': 0.16; 'look-up': 0.16;
'message-id:@DancesWithMice.info': 0.16; 'not)': 0.16; 'recall':
0.16; 'received:51.254': 0.16; 'received:51.254.211': 0.16;
'received:51.254.211.219': 0.16; 'received:cloud': 0.16;
'received:rangi.cloud': 0.16; 'sets,': 0.16; 'shuffling': 0.16;
'somewhat': 0.16; 'spending': 0.16; 'stacks': 0.16; 'strings,':
0.16; 'subject:() ': 0.16; 'subject:dictionaries': 0.16;
'whichever': 0.16; 'whilst': 0.16; 'wrote:': 0.16; 'python': 0.16;
'tue,': 0.18; "aren't": 0.20; 'maybe': 0.20; 'programming': 0.21;
"i've": 0.22; 'to:addr:python-list': 0.23; 'science': 0.24;
'anything': 0.24; 'student': 0.24; 'idea': 0.25; '>>>': 0.26;
'chris': 0.26; 'computer': 0.26; 'concept': 0.27; 'jun': 0.27;
'studies': 0.27; 'single': 0.28; 'module': 0.28; "didn't": 0.29;
"isn't": 0.29; '(and': 0.30; 'header:User-Agent:1': 0.31;
'header:Organization:1': 0.31; 'there': 0.31; 'think': 0.31;
'stuff': 0.31; 'but': 0.31; 'expect': 0.31; 'fixed': 0.31;
'question': 0.32; "i'm": 0.32; 'difference': 0.32; 'do.': 0.32;
'research.': 0.32; 'said,': 0.32; 'using': 0.33; 'reliance': 0.33;
'header:In-Reply-To:1': 0.33; 'subject:for': 0.33; 'same': 0.34;
'necessarily': 0.35; 'level.': 0.35; 'yes,': 0.35; 'trying': 0.36;
'our': 0.63; 'received:userid': 0.64; 'your': 0.64; 'skip:r 20':
0.64; 'seen': 0.65; 'becomes': 0.65; 'reserve': 0.65; 'talking':
0.65; 'thus': 0.65; 'visited': 0.65; 'well': 0.66; 'look': 0.66;
'similar': 0.66; 'right': 0.66; 'great': 0.67; 'years': 0.67;
'order': 0.68; 'time,': 0.69; 'compare': 0.69; 'everything,':
0.69; 'latter': 0.69; 'took': 0.70; 'skip:e 20': 0.70; 'seek':
0.71; 'longer': 0.72; 'operations': 0.74; 'favor': 0.77;
'received:51': 0.77; 'received:localhost.localdomain': 0.77;
'....': 0.81; 'received:localdomain': 0.81; 'field': 0.82; '2021':
0.84; 'talent': 0.84; "'good'": 0.84; "'the": 0.84; 'days!': 0.84;
'entered': 0.84; 'exhibit': 0.84; 'experiments': 0.84; 'implies':
0.84; 'motivation': 0.84; 'recalled': 0.84; 'received:47': 0.84;
'thus,': 0.84; 'greater': 0.91; 'largely': 0.91; 'occasion': 0.91;
'friends': 0.96
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on vps517507.ovh.net
X-Spam-Level:
X-Spam-Status: No, score=-3.0 required=5.0 tests=ALL_TRUSTED,BAYES_00,
DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,NICE_REPLY_A autolearn=ham
autolearn_force=no version=3.4.0
DKIM-Filter: OpenDKIM Filter v2.11.0 mail.rangi.cloud 2E68C24AB
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1623819950;
bh=a8/w3YXFq83YN/q3i+tg1tEuNRPUwV+guWTIrSMSPGg=;
h=Subject:To:References:From:Date:In-Reply-To:From;
b=XCA80ibbtYBRiTO7X1wQAS313BLGdSYz84B1HT3kQy+pTi96KPw3+IKnUEcdX8hih
T91mWLRRiC9Uvi7CdDwRmBZLwVNogVn6iyktwAbeLBPlnHwx/LC4kOi5ciThPDiu6U
+x1ps6Q7ypl0CCqZebdIHlmPG87GFKUVf28vGNGBtIlSUKiBs8VGHb8w6EHIO5k0J7
2izJdoltSatOZAHL8gYsdGGgstUJ/74xjfQLMYY/2eRntt5waeYrWgmt4NF5n/aYUf
iHuoFlL47P5KMoM7B8/2S+mIvJF5KdrsnitnephLz2/iynMMdaHZsA+FwIF5LELQew
AmCAf1j2f/0Jg==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
In-Reply-To: <LrGdnYY_vvki6VX9nZ2dnUU78cnNnZ2d@brightview.co.uk>
Content-Language: en-GB
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <12ae29a6-d96a-7075-6554-29e741aa5f73@DancesWithMice.info>
X-Mailman-Original-References: <r_idneymiJJrslv9nZ2dnUU78TfNnZ2d@brightview.co.uk>
<iioeq6Fl58bU1@mid.individual.net>
<fMqdnQ1XkJMgiFr9nZ2dnUU78UPNnZ2d@brightview.co.uk>
<CAPTjJmpfgiQB=dx8H4iiutBjzEQqZAM8CxuNLHLy9B2GAVK+wg@mail.gmail.com>
<mailman.37.1623699830.4164.python-list@python.org>
<0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk>
<0184de41-3482-c576-60ed-343fbe0fe73d@DancesWithMice.info>
<mailman.43.1623712309.4164.python-list@python.org>
<LrGdnYY_vvki6VX9nZ2dnUU78cnNnZ2d@brightview.co.uk>
 by: dn - Wed, 16 Jun 2021 05:04 UTC

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
> the documentation for dequeue when I want to use it. For lists, sets and
> dictionaries, I don't expect to look at the documentation and pop()
> seemed a good bet for what I wanted to do.

"What I expect" (aka 'dim/dusty recollection' or 'gut feel') is a good
way to learn - match it with the Python REPL and a couple of experiments
to 'prove' your expectation/recollection. Thereafter there is a far
greater likelihood of "learning" - and remembering-correctly 'next time'...

The other worthy technique in this field is "deliberate learning". Thus,
spending some time studying the docs for the built-ins' functionality
(and experimentation) to obviate the need to look-up that level of
documentation.

Contrary to the learning-practices of 'our day', these days there is a
far lower reliance on memory, in favor of rapid-access to reference
data, eg the Python docs and REPL's help(), etc. Accordingly, the 'bits'
that we might think of as 'minimum knowledge' may be seen as somewhat
"arbitrary".
(actually it is called Curriculum Design, but given that there is no
single application-area for Python there is no single curriculum either)

No matter: we are completely correct, no question - and what would
'they' know anyway?

PS we were also subject to the idea that intelligence/ability was
largely genetic and thus only available in a fixed quantity - either one
is 'good' at something, or not (full stop). These days we know ourselves
(brains) to be more "plastic", and that with sufficient motivation and
effort we can learn 'new stuff', regardless of whether we were 'good at
it' yesterday!

>> I don't know if you are ComSc student or not, but there isn't even
>> consistency at the theoretical level. I first arrived at the concept of
>> "queuing" and "dequeuing" (NB the latter is not the same as the Python
>> Collections module "deque" library) whilst studying Queue Theory in
>> Operations Research. At about the same time, my ComSc studies took me
>> into "stacks".
>
> My student days are well over (about 60 years over).

Someone with an even longer beard than mine! We could compare walking
sticks...

Oh wait, aren't we talking about Python.

I'm amazed at how stuff from 'history' is recyclable and becomes
applicable to whichever is described as 'today'. Even 'new' things in
computing!

There's always something new to adapt, if not learn...

....

> Yes, but we can still seek consistency where it is possible

Trouble is, there are different ways of looking at 'stuff', and thus
different dimensions of "consistent".

Thus, dict methods try to be consistent to the way a dict behaves.
Whereas being 'consistent' with other collections: sets, lists, strings,
etc; comes second. Oops if not OOPs!

>> Having entered the queue-of-life a long time ago, and shuffling ever
>> closer to 'the end of the line', this memory-challenged 'silver-surfer'
>> prefers to reserve pop() for straightforward stacks and lists, which
>> implies quite enough inconsistency, without trying to convolute my mind
>> to pop()-ing dicts, sets (or 'worse'!).

I still haven't recalled a single occasion when I've used set.pop() or
dict.pop(). Was that because I didn't recall their availability at the
right time, or does my mind simply not see that 'consistency' yours
recognises?
(not that it matters particularly)

>> That said, whether I actually use dict.pop() or not, these 'features'
>> which are consistent in name but not necessarily in arguments or
>> effects, contribute to Python's great flexibility and power! Thank
>> goodness for help() and the Python docs...
>
> I don't like 'pop's at all since it meant that a valve had exploded on
> the Ferranti Pegasus that was my first encounter with computers.

That does pre-date the prehistoric computers I managed to play-with!

There's apparently one in LON's Science Museum. Don't know if it was
there when I last visited (c.15 years ago) - I do recall their Babbage
implementations and an analog computer (looked like some torture rack)
similar to one that my father used way, way, way-back. Similarly,
considering it/another similar exhibit and talking with our friends
about the 'joys' of using paper tape (and its talent for wrapping itself
around anything and everything, except where you wanted it) and those of
(assembler) programming delays in order to store data on rotating
mag-drums.

Those were the days!
(or maybe not)
--
Regards,
=dn


devel / comp.lang.python / Re: Behaviour of pop() for dictionaries

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor