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
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

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

Re: Tuple unpacking inside lambda expressions

2022-04-20 Thread Albert-Jan Roskam
On Apr 20, 2022 13:01, Sam Ezeh wrote: I went back to the code recently and I remembered what the problem was. I was using multiprocessing.Pool.pmap which takes a callable (the lambda here) so I wasn't able to use comprehensions or starmap Is there anything for

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

RE: lambda issues

2022-04-20 Thread Schachner, Joseph
Re: "...which takes a callable (the lambda here)" Python lamdas have some severe restrictions. In any place that takes a callable, if a lambda can't serve, just use def to write a function and use the function name. Joseph S. Teledyne Confidential; Commercially Sensitive Business Data

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-20 Thread Loris Bennett
Dennis Lee Bieber writes: > On Tue, 19 Apr 2022 15:51:09 +0200, "Loris Bennett" > declaimed the following: > >>If I am merely trying to represent part a very large number of seconds >>as a number of years, 365 days per year does not seem that controversial > > The Explanatory Supplement

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-20 Thread Loris Bennett
Random832 writes: > On Tue, Apr 19, 2022, at 07:11, Loris Bennett wrote: >> I now realise that timedelta is not really what I need. I am >> interested solely in pure periods, i.e. numbers of seconds, that I >> can convert back and forth from a format such as > > A timedelta *is* a pure period.

Re: Tuple unpacking inside lambda expressions

2022-04-20 Thread Sam Ezeh
I went back to the code recently and I remembered what the problem was. I was using multiprocessing.Pool.pmap which takes a callable (the lambda here) so I wasn't able to use comprehensions or starmap Is there anything for situations like these? Kind Regards, Sam Ezeh On Sat, 16 Apr 2022 at

Re: Tuple unpacking inside lambda expressions

2022-04-20 Thread Sam Ezeh
This also works great! Kind Regards, Sam Ezeh On Tue, 19 Apr 2022 at 12:03, Antoon Pardon wrote: > > Op 16/04/2022 om 23:36 schreef Sam Ezeh: > > Two questions here. > > > > Firstly, does anybody know of existing discussions (e.g. on here or on > > python-ideas) relating to unpacking inside

Enums and nested classes

2022-04-20 Thread Sam Ezeh
Hello everyone, Has anyone here used or attempted to use a nested class inside an enum? If so, how did you find it? (what did you expect to happen and did your expectations align with resulting behaviour etc.) Here are two examples describing the situation I'm talking about ``` class

Re: Proposal: Syntax for attribute initialisation in __init__ methods

2022-04-20 Thread Sam Ezeh
I'll see if I can find out how positional only and keyword only arguments are used in __init__ methods in the wild and I'll see if there have been any other discussions talking about what this approach could offer. On Sun, 17 Apr 2022 at 02:54, dn wrote: > > On 17/04/2022 09.20, Sam Ezeh wrote: