Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

No wonder Clairol makes so much money selling shampoo. Lather, Rinse, Repeat is an infinite loop!


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

SubjectAuthor
o Re: Why no list as dict key?Sam Ezeh

1
Re: Why no list as dict key?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: sam.z.e...@gmail.com (Sam Ezeh)
Newsgroups: comp.lang.python
Subject: Re: Why no list as dict key?
Date: Wed, 20 Apr 2022 20:28:41 +0100
Lines: 56
Message-ID: <mailman.172.1650482935.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>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de 5J4/Bo+xdRts/glTb30GGAnKAengzy7VH22p+lu1PROA==
Return-Path: <sam.z.ezeh@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=qYtAXDJC;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'url-ip:140.82/16': 0.03;
'def': 0.04; 'traceback': 0.04; '(most': 0.05; '2022': 0.05;
'last):': 0.05; 'subject:Why': 0.07; 'underlying': 0.07; 'linux':
0.09; 'so?': 0.09; 'subject:list': 0.11; 'url:github': 0.14;
'import': 0.15; 'url:mailman': 0.15; 'url-ip:140/8': 0.15;
'2022,': 0.16; 'dictionary.': 0.16; 'hash': 0.16; 'janhangeer':
0.16; 'key,': 0.16; 'mauritius': 0.16; 'wrote:': 0.16; 'python':
0.16; 'github': 0.17; 'values': 0.17; 'to:addr:python-list': 0.20;
'skip:_ 10': 0.22; 'list,': 0.24; 'url-ip:188.166.95.178/32':
0.25; 'url-ip:188.166.95/24': 0.25; 'url:listinfo': 0.25;
'cannot': 0.25; 'url-ip:188.166/16': 0.25; 'url-ip:51/8': 0.26;
'>>>': 0.28; 'blog': 0.30; 'url-ip:188/8': 0.31; '"",': 0.32;
'received:209.85.214': 0.32; 'message-id:@mail.gmail.com': 0.32;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'using': 0.37; 'received:209.85':
0.37; 'class': 0.37; 'file': 0.38; 'thanks': 0.38; 'received:209':
0.39; 'list': 0.39; 'use': 0.39; 'wed,': 0.39; 'happen': 0.40;
'skip:h 10': 0.61; 'above': 0.62; 'here': 0.62; 'key': 0.64;
'change.': 0.69; 'skip:f 30': 0.71; '....': 0.76;
'received:209.85.214.195': 0.84; 'received:mail-
pl1-f195.google.com': 0.84; 'tables': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=0iH4rporcnBCB0o/5qQUeRJsAb0vef9oPQgYGF0++xI=;
b=qYtAXDJCokrQi2EAByxmqCZBrO1hq51d50nAKf0NW0iY6W+os42LyDv4zQ+Fk3t+Qr
8MsNcZ10lfE9Wd02rAwFUQO8jLGKcMe7wYPguR1sQe0KSyKIxhG0IlJjl8CH6VmmawHS
GVy78i83CaP5WDWqf6J+OTua2HheJnEgTw1omnwnx0yabrverppQVrED3a11cHt3yFqW
dJkO1XAfD+E5vMDMf3IJKlCujlrEvfszupFMWII8FYw4Vo4MaPerhn9qfgFCfrUEoBIV
iK1MplonBlosbyGFVYg5HafMm3a7oKs5BclfjGTpNRUAe1TR7+EidjM58qS5OQ+Ohcar
Nx4A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=0iH4rporcnBCB0o/5qQUeRJsAb0vef9oPQgYGF0++xI=;
b=XIUAm91AJr/YPr+FMTXr8oC83BT7gEcx0Vl3Z507d9iqtBK4JcA18+dzq/cemyXvNc
44oBR99UwmaRKLzhvw+Jxm71F4zi3ebPD7EP5j3wwPzNi+686js77W2NfrgZJpK66V9n
DWcAAh19+K6VGMK0C4MimaBfsqJXunBeFwmruQ5FuWXUWM7hd4eVcmnA3EnieRD5BXSD
DyyOYU6XzFXsg/EadrA9TaasICGn/MFLvmyvI6Mel9CDf1YZbVLD2B9eMbqZrRbiGDiE
+HFM5EOm4PXHd6piZY46ZYk0kOVKkpGZIex16nKy0NDWASEQyRnGINITouc3XBrI6XPd
Du6Q==
X-Gm-Message-State: AOAM530kq6LugkCF+te5soeM45QHO1GIl9eNAUUsyahDfTgSBZVNj7kT
bL4cbrRcst1P/I9CGsyzTgyyc1bcL7XwYxkWoQoY07YGVWtT5Q==
X-Google-Smtp-Source: ABdhPJwVF5UY27tqnZDer42EbOZXgb6HPn5RnLgEOSpei//fxF5ffjKiqP3aqtdqBlY7LkKIwaKI/SiQtyTku0cKsAQ=
X-Received: by 2002:a17:90a:c3:b0:1ca:54c1:a684 with SMTP id
v3-20020a17090a00c300b001ca54c1a684mr6072600pjd.148.1650482932206; Wed, 20
Apr 2022 12:28:52 -0700 (PDT)
In-Reply-To: <CADrxXXmWEjmQmR0-mP7tugrEJ1YhqBCt_X-57fumqft4=rNPYw@mail.gmail.com>
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: <CAD+b3HiODpHznuK3a_OpH_cn-Dw2dS6mZ6=fzfsO3U-35===tw@mail.gmail.com>
X-Mailman-Original-References: <CADrxXXmWEjmQmR0-mP7tugrEJ1YhqBCt_X-57fumqft4=rNPYw@mail.gmail.com>
 by: Sam Ezeh - Wed, 20 Apr 2022 19:28 UTC

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.

```
[sam@samtop]: ~>$ python
Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import functools
>>> import operator
>>> class HashableList(list):
.... def __hash__(self):
.... return functools.reduce(operator.xor, [key * value for
key, value in enumerate(self)], 5)
....
>>> x = HashableList([1,2,3])
>>> y = HashableList([1,2,3])
>>> dictionary = {x: 5}
>>> dictionary
{[1, 2, 3]: 5}
>>> dictionary[x]
5 >>> dictionary[y]
5 >>> x.append(4)
>>> dictionary
{[1, 2, 3, 4]: 5}
>>> dictionary[x]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: [1, 2, 3, 4]
>>> dictionary[y]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: [1, 2, 3]
>>>
```

On Wed, 20 Apr 2022 at 19:23, Abdur-Rahmaan Janhangeer
<arj.python@gmail.com> wrote:
>
> Greetings list,
>
> Using Python3.9, i cannot assign a list [1, 2] as key
> to a dictionary. Why is that so? Thanks in advanced!
>
> Kind Regards,
>
> Abdur-Rahmaan Janhangeer
> about <https://compileralchemy.github.io/> | blog
> <https://www.pythonkitchen.com>
> github <https://github.com/Abdur-RahmaanJ>
> Mauritius
> --
> https://mail.python.org/mailman/listinfo/python-list

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor