Re: Why no list as dict key?

2022-04-25 Thread Lars Liedtke
Thx, didn't see it that way yet. -- Lars Liedtke Software Entwickler Phone: Fax:+49 721 98993- E-mail: l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany Marken der solute GmbH | brands of solute GmbH

Re: Why no list as dict key?

2022-04-25 Thread Peter J. Holzer
On 2022-04-25 15:13:19 +0200, Lars Liedtke wrote: > May I stupidly ask, why one would want to use an iterable (even immutable) > as dict key? A string is also an immutable iterable, so this is probably even the most common case. As for more complex data structures: * Tuples or immutable dicts

Re: Why no list as dict key?

2022-04-25 Thread Lars Liedtke
May I stupidly ask, why one would want to use an iterable (even immutable) as dict key? I thought keys were meant to be something "singular". And yes you could also combine a string to be a key, and if you combine a string it would be somehow the same as a tuple. But anyways I still fail to

Re: Why no list as dict key?

2022-04-20 Thread Abdur-Rahmaan Janhangeer
As clear as daylight, thanks! Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius -- https://mail.python.org/mailman/listinfo/python-list

Re: Why no list as dict key?

2022-04-20 Thread Chris Angelico
On Thu, 21 Apr 2022 at 13:23, Abdur-Rahmaan Janhangeer wrote: > > Assumes checking for object equality before inserting. > If they are they same, do we need different hashes? > The point of the hash is to find things that are equal. That's why 1234, 1234.0, and 0j+1234.0 all have the same hash.

Re: Why no list as dict key?

2022-04-20 Thread Dan Stromberg
On Wed, Apr 20, 2022 at 7:23 PM Abdur-Rahmaan Janhangeer < arj.pyt...@gmail.com> wrote: > Maybe hashes should point to an object rather than being the hash of an > object themselves. > Maybe the speed drop is not worth it. > If you need mutable keys, you /might/ create a dict-like-object using

Re: Why no list as dict key?

2022-04-20 Thread Abdur-Rahmaan Janhangeer
Assumes checking for object equality before inserting. If they are they same, do we need different hashes? Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius On Thu, Apr

Re: Why no list as dict key?

2022-04-20 Thread 2QdxY4RzWzUUiLuE
On 2022-04-21 at 06:22:53 +0400, Abdur-Rahmaan Janhangeer wrote: > Maybe hashes should point to an object rather than being the hash of an > object themselves. > Maybe the speed drop is not worth it. Then you have a different problem. x = [1, 2, 3] y = [n for n in 1, 2, 3] Those two

Re: Why no list as dict key?

2022-04-20 Thread Abdur-Rahmaan Janhangeer
Thanks everybody, In the the event spam is appended a value, then looking for [1,2] does not return anything but looking for [1,2,3] yes. But i gather the way dictionaries are implemented makes it difficult to do so ... Maybe hashes should point to an object rather than being the hash of an

Re: Why no list as dict key?

2022-04-20 Thread Greg Ewing
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.

Re: Why no list as dict key?

2022-04-20 Thread Greg Ewing
On 21/04/22 6:22 am, Abdur-Rahmaan Janhangeer wrote: Using Python3.9, i cannot assign a list [1, 2] as key to a dictionary. Why is that so? If the contents of the list were to change after using it as a key, its hash value would no longer match its position in the dict, so subsequent lookups

Re: Why no list as dict key?

2022-04-20 Thread Chris Angelico
On Thu, 21 Apr 2022 at 06:20, Avi Gross via Python-list wrote: > > 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. > Yes.

Re: Why no list as dict key?

2022-04-20 Thread Avi Gross via Python-list
ing.  Life is complicated. Then you die. -Original Message- From: Chris Angelico 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 wrote: > > Repeating the above points, here is an example of what would

Re: Why no list as dict key?

2022-04-20 Thread Chris Angelico
On Thu, 21 Apr 2022 at 05:30, Sam Ezeh 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. > >

Re: Why no list as dict key?

2022-04-20 Thread Sam Ezeh
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,

Re: Why no list as dict key?

2022-04-20 Thread Chris Angelico
On Thu, 21 Apr 2022 at 04:23, Abdur-Rahmaan Janhangeer wrote: > > Greetings list, Greetings tuple, > Using Python3.9, i cannot assign a list [1, 2] as key > to a dictionary. Why is that so? Thanks in advanced! > Because a list can be changed, which would change what it's equal to: >>> spam =

Re: Why no list as dict key?

2022-04-20 Thread Larry Martell
On Wed, Apr 20, 2022 at 2:23 PM Abdur-Rahmaan Janhangeer 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! Dict keys cannot be mutable. Use a tuple instead. --

Why no list as dict key?

2022-04-20 Thread Abdur-Rahmaan Janhangeer
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 | blog github