Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

* gb notes that fdisk thinks his cdrom can store one terabyte -- Seen on #Linux


devel / comp.lang.python / Re: Why no list as dict key?

SubjectAuthor
* Re: Why no list as dict key?Avi Gross
`- Re: Why no list as dict key?Greg Ewing

1
Re: Why no list as dict key?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: avigr...@verizon.net (Avi Gross)
Newsgroups: comp.lang.python
Subject: Re: Why no list as dict key?
Date: Wed, 20 Apr 2022 20:18:49 +0000 (UTC)
Lines: 61
Message-ID: <mailman.174.1650485933.20749.python-list@python.org>
References: <CADrxXXmWEjmQmR0-mP7tugrEJ1YhqBCt_X-57fumqft4=rNPYw@mail.gmail.com>
<CAD+b3HiODpHznuK3a_OpH_cn-Dw2dS6mZ6=fzfsO3U-35===tw@mail.gmail.com>
<CAPTjJmqQC30Z_3qErkDbyEcTv843nuWN5AJH6tkXb+7V85z3Dg@mail.gmail.com>
<1278120400.1002892.1650485929612@mail.yahoo.com>
Reply-To: Avi Gross <avigross@verizon.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de DCu+ylz0St62F2Ak1ihk0AVLyqm8ewS0Bu6Jde/qLHqg==
Return-Path: <avigross@verizon.net>
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=verizon.net header.i=@verizon.net header.b=HXVn3nde;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.006
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'def': 0.04; '2022': 0.05;
'&gt;&gt;&gt;': 0.07; 'queue': 0.07; 'subject:Why': 0.07;
'underlying': 0.07; 'angelico': 0.09; 'converting': 0.09;
'items.': 0.09; 'obviously': 0.09; 'solution,': 0.09;
'subject:list': 0.11; 'url:mailman': 0.15; 'problem.': 0.15;
'chrisa': 0.16; 'conversion': 0.16; 'derivative': 0.16; 'dict':
0.16; 'dictionary.': 0.16; 'hash': 0.16; 'item,': 0.16; 'key,':
0.16; 'nested': 0.16; 'repeatedly.': 0.16; 'rules.': 0.16;
'situations.': 0.16; 'something.': 0.16; 'to\xc2\xa0': 0.16;
'tuple': 0.16; 'typographic': 0.16; 'ways.': 0.16; 'wrote:': 0.16;
'reached': 0.17; 'values': 0.17; 'thu,': 0.19; 'to:addr:python-
list': 0.20; 'skip:_ 10': 0.22; 'list,': 0.24; "i'd": 0.24;
'to:name:python-list@python.org': 0.24; 'skip:- 10': 0.25; 'url-
ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'discussion': 0.25; 'url:listinfo': 0.25; 'url-ip:188.166/16':
0.25; 'tried': 0.26; '>>>': 0.28; 'chris': 0.28; 'thinking': 0.28;
'example,': 0.28; 'keeping': 0.28; 'attempt': 0.31; 'deep': 0.31;
'raise': 0.31; 'url-ip:188/8': 0.31; 'program': 0.31; 'question':
0.32; 'deleted': 0.32; 'structure': 0.32; 'unless': 0.32; 'but':
0.32; 'same': 0.34; 'mean': 0.34; 'skip:" 20': 0.34; 'header:In-
Reply-To:1': 0.34; 'trying': 0.35; 'complex': 0.35; 'item': 0.35;
'applying': 0.36; 'change': 0.36; 'lists': 0.37; "it's": 0.37;
'class': 0.37; 'way': 0.38; 'adding': 0.39; 'ago': 0.39; 'list':
0.39; 'use': 0.39; 'wed,': 0.39; 'wrote': 0.39; 'copy.': 0.40;
'define': 0.40; 'forms': 0.40; 'happen': 0.40; 'otherwise,': 0.40;
'both': 0.40; 'something': 0.40; 'want': 0.40; 'try': 0.40; 'law':
0.60; 'method': 0.61; 'skip:h 10': 0.61; 'above': 0.62; 'from:':
0.62; 'to:': 0.62; 'here': 0.62; 'data,': 0.63; 'imagine': 0.64;
're:': 0.64; 'your': 0.64; 'top': 0.65; '20,': 0.67; 'items':
0.68; 'change.': 0.69; 'skip:f 30': 0.71; '....': 0.76; 'life':
0.77; 'sent:': 0.78; 'header:Reply-To:1': 0.79; '(such': 0.84;
'ages': 0.84; 'converted': 0.84; 'die.': 0.84; 'equation': 0.84;
'inclined': 0.84; 'integral': 0.84; 'keys?': 0.84; 'maintains':
0.84; 'tables': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verizon.net; s=a2048;
t=1650485931; bh=/2ivhdlnFSji6coJ8fJhuLtFuof0m18MRr3PnG9qSHY=;
h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject:Reply-To;
b=HXVn3ndeIyRuUW2lqLIeZeROo3AFQ/d/FCtGirPV6xMvKs26rANXAg3erMKY3OdGesisftAyPOC71jwuWfQzOWBjnXzCiZHiZ/8YMwIilxpgnHhgnHJxN4x7mO6DTnq67bvvHNU19y7ylnq7kuQdN9mJ6cu9vkMgAbWFTn6A1QxrJIEITJgHUt4BV5SpNkHd/Wx1zXhwXLHKkpNmggk5M+WDt90voty0NenyW/OGEait9As5Pglp7K1HmrnhqoybW+L+0WGBnmc65mP7TkvjAiNT2bwR41lx5AiK6VKtLVYM22jsd7NXXdE8rdpr1hFfrrMSGpGH8Gk88Cc1EuMRCA==
X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
t=1650485931; bh=tcBz3x6/2585Mbo9k4cRLnVn+MfiYNyKniju/pWjzpB=;
h=X-Sonic-MF:Date:From:To:Subject:From:Subject;
b=S9FlaOi+1nI5XNB8gMfmzxHkXCSGGVGpSoeWOhrIMTvP9if87fBqKqHiJKmFCeHw/ohxspzHgd0REebOWV2iJ5K5RpSGlkXBzfDK07Cq0Er94lBHI6H7SqFm8fw6/mIXTAW1h0hCrVDmznTldKPpJcykojP7wlO1C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NYp4Us2c37YXdVvXFL3fQiLkAu.
.cmkTcFcD3mHVljW72X5RUOtrjFGqrvv1CqyxU2bv2uQM8uWoi3UBDJli7h60BT2nr4FMHJhfe4Y
6nSFJY1hDBuBi5hMrane.06Oox2EdLRKYP0I2XHIqsxgLnDeQepAvuULU07AA3ZhtnbkbjNNY3O1
Oo3HFoq.jqvBvKOixIw3J82qLnn_bPM2ukiuNpfkxlYoJ17TZeBAqyRR_o1_brRVE9wJwKbDXUos
q2.uQqqmdmQNYQPDZDKku_gyJ06d7liFUWO8Yy806qy5TUEwonVRjfgnbW8c3pz6Iz.oYX1wYQCt
8cA--
X-Sonic-MF: <avigross@verizon.net>
In-Reply-To: <CAPTjJmqQC30Z_3qErkDbyEcTv843nuWN5AJH6tkXb+7V85z3Dg@mail.gmail.com>
X-Mailer: WebService/1.1.20048 aolwebmail
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <1278120400.1002892.1650485929612@mail.yahoo.com>
X-Mailman-Original-References: <CADrxXXmWEjmQmR0-mP7tugrEJ1YhqBCt_X-57fumqft4=rNPYw@mail.gmail.com>
<CAD+b3HiODpHznuK3a_OpH_cn-Dw2dS6mZ6=fzfsO3U-35===tw@mail.gmail.com>
<CAPTjJmqQC30Z_3qErkDbyEcTv843nuWN5AJH6tkXb+7V85z3Dg@mail.gmail.com>
 by: Avi Gross - Wed, 20 Apr 2022 20:18 UTC

This does raise an issue, Chris, if you use the method of making a tuple companion for a list at a specific time just for use as a dictionary key, then later change the list, you can end up with various situations.
Obviously the changed list can not only not access the stored item, but if converted again to a tuple, may address a different item. I can see many scenarios with abandoned dictionary items that are never deleted and can only be reached by examining all items in the dictionary.
So mutability is only one concern. If you actually mutate your data, ...
I am thinking as an example about a program I wrote ages ago that deals with equations in symbolic form and maintains a collection of forms of the equation it is trying to take a derivative or integral of by applying an assortment of typographic rules. I mean commutative lawand others.. You do not want to  keep adding the same item into the data structure (such as a queue) repeatedly. So something like a dictionary (or set) can be a good way to store unique items. But the items are some complex lists so the above discussion qualifies. Of course the tuple conversion for a nested structure would need to have made a deep copy. 
The question in the above is how to make sure that taking a next attempt off the queue deals with the dictionary of tried items. In this case, unless you use it to find a solution, keeping it in the dictionary to avoid repeating, makes sense. 
And another thought is that mapping a list to a tuple has another possible drawback.
What if I have both a list and tuple with the same structure which I want as keys?
I can imagine then converting the list in some imaginative ways. For example, embed the list in another list whose first item is "from-tuple" or something. 
Life is complicated. Then you die.

-----Original Message-----
From: Chris Angelico <rosuav@gmail.com>
To: python-list@python.org
Sent: Wed, Apr 20, 2022 3:49 pm
Subject: Re: Why no list as dict key?

On Thu, 21 Apr 2022 at 05:30, Sam Ezeh <sam.z.ezeh@gmail.com> wrote:
>
> Repeating the above points, here is an example of what would happen if
> you tried. Dictionaries require their keys to be immutable as
> under-the-hood they use hash tables and they'd fail when the
> underlying values are allowed to change.
>
> ```
> >>> class HashableList(list):
> ...    def __hash__(self):
> ...            return functools.reduce(operator.xor, [key * value for
> key, value in enumerate(self)], 5)

Quickie: I'd be inclined to define hash on top of a tuple's hash,
rather than try to design my own and hope that it's suitable. "return
hash(tuple(self))" is a good demonstration of the parallel.

Otherwise, good demonstration of the problem.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list

Re: Why no list as dict key?

<jcbserFtv2U1@mid.individual.net>

  copy mid

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

  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: Why no list as dict key?
Date: Thu, 21 Apr 2022 14:05:12 +1200
Lines: 11
Message-ID: <jcbserFtv2U1@mid.individual.net>
References: <CADrxXXmWEjmQmR0-mP7tugrEJ1YhqBCt_X-57fumqft4=rNPYw@mail.gmail.com>
<CAD+b3HiODpHznuK3a_OpH_cn-Dw2dS6mZ6=fzfsO3U-35===tw@mail.gmail.com>
<CAPTjJmqQC30Z_3qErkDbyEcTv843nuWN5AJH6tkXb+7V85z3Dg@mail.gmail.com>
<1278120400.1002892.1650485929612@mail.yahoo.com>
<mailman.174.1650485933.20749.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net IxcoLfL0rE8U9nnFzyepEgGOwND8cctdGCdB3s4jPGbBBwNn7M
Cancel-Lock: sha1:aq7RoIRr7KLjp6gVQEDVFgTj7SE=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <mailman.174.1650485933.20749.python-list@python.org>
 by: Greg Ewing - Thu, 21 Apr 2022 02:05 UTC

On 21/04/22 8:18 am, Avi Gross wrote:
> I am thinking as an example about a program I wrote ages ago that deals with equations in symbolic form and maintains a collection of forms of the equation it is trying to take a derivative or integral of by applying an assortment of typographic rules.

It sounds like you would be better off making all your equation data
structures immutable. Instead of mutating the equation when making
a transformation, return a new equation. Then you can use sets and
dicts to cache them etc. without any problems.

--
Greg

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor