[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-08-31 Thread Steven D'Aprano
On Mon, Aug 31, 2020 at 04:01:06AM -, junkneno...@gmail.com wrote: > I have a use case which relates to this request: iterating over a dict > starting from a given key. I would like to achieve this without having > to pay the full O(n) cost if I'm going to be iterating over only a few >

[Python-ideas] Re: PEP 472 - new dunder attribute, to influence item access

2020-08-31 Thread Random832
On Mon, Aug 31, 2020, at 02:45, Greg Ewing wrote: > On 31/08/20 3:35 pm, Random832 wrote: > > > x[(1,)] old arg=(1,); new args=((1,),)? > > x[(1,2)] old arg=(1,2); new args=((1,2),)? > > No, I proposed *not* to do those -- putting parens around the > arguments would continue to make no

[Python-ideas] Re: PEP 472 - new dunder attribute, to influence item access

2020-08-31 Thread Ricky Teachey
On Mon, Aug 31, 2020 at 11:38 AM Guido van Rossum wrote: > On Sun, Aug 30, 2020 at 11:33 PM Christopher Barker > wrote: > >> I *think* the trailing comma is shorthand for a larger class of problems. >> That is, in the current system, you can only put a single expression in the >> [], so a comma

[Python-ideas] Re: PEP 472 - new dunder attribute, to influence item access

2020-08-31 Thread Guido van Rossum
On Mon, Aug 31, 2020 at 12:09 AM Greg Ewing wrote: > I'm wondering whether parens should be required when there are both > keyword args and more than one positional arg in an index. I.e instead > of > > a[1, 2, k = 3] > > you would have to write > > a[(1, 2), k = 3] > I think this

[Python-ideas] Re: PEP 472 - new dunder attribute, to influence item access

2020-08-31 Thread Guido van Rossum
On Sun, Aug 30, 2020 at 11:56 PM Greg Ewing wrote: > On 31/08/20 4:11 pm, Guido van Rossum wrote: > > Okay, and if I write > > a.__getitem__((1, 3), k=2) will the function see the same thing? > > No, it will see (i, j, k) == (1, 3, 2). > That was a typo. I meant to ask whether

[Python-ideas] Re: PEP 472 - new dunder attribute, to influence item access

2020-08-31 Thread Guido van Rossum
On Sun, Aug 30, 2020 at 11:33 PM Christopher Barker wrote: > I *think* the trailing comma is shorthand for a larger class of problems. > That is, in the current system, you can only put a single expression in the > [], so a comma creates a tuple. Which means that: > > i = (a,) > thing[i] = x > >

[Python-ideas] Re: argmax and argmin to python list

2020-08-31 Thread Robin Becker
On 31/08/2020 01:14, Christopher Barker wrote: or use numpy:-) (which is probably where the name "argmin" came from, rather than "index_min") https://en.wikipedia.org/wiki/Arg_max not sure if numpy precedes my own first memory of these functions in the 1970's, but it's fairly obvious that

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-08-31 Thread junknenopok
I have a use case which relates to this request: iterating over a dict starting from a given key. I would like to achieve this without having to pay the full O(n) cost if I'm going to be iterating over only a few items. My understanding is that this should be achievable without needing to

[Python-ideas] Re: argmax and argmin to python list

2020-08-31 Thread Jeff Allen
On 31/08/2020 01:14, Christopher Barker wrote: On Sun, Aug 30, 2020 at 7:28 AM Barry > wrote: How is it supposed to work with set or dict or other iterables without clear order? see the discussion in another recent thread about making dict indexable --

[Python-ideas] Re: argmax and argmin to python list

2020-08-31 Thread Antoine Pitrou
On Sun, 30 Aug 2020 09:51:14 +0100 Barry Scott wrote: > That is 4x slower then my code for 1,000,000 items. This is highly dependent on the cost of equality checks, therefore on the type being compared. Regards Antoine. ___ Python-ideas mailing list

[Python-ideas] Re: PEP 472 - new dunder attribute, to influence item access

2020-08-31 Thread Joseph Martinot-Lagarde
Guido van Rossum wrote: > You appear to be making a connection between star-args in a call and in a > function definition. They are unrelated. I initially thought that indexing was more function-like with a bit of magic to handle one or multiple arguments, and I was wondering if this "magic" can

[Python-ideas] Re: PEP 472 - new dunder attribute, to influence item access

2020-08-31 Thread Ricky Teachey
On Mon, Aug 31, 2020, 3:10 AM Greg Ewing wrote: > I'm wondering whether parens should be required when there are both > keyword args and more than one positional arg in an index. I.e instead > of > > a[1, 2, k = 3] > > you would have to write > > a[(1, 2), k = 3] > > That would make it

[Python-ideas] Re: PEP 472 - new dunder attribute, to influence item access

2020-08-31 Thread Christopher Barker
On Mon, Aug 31, 2020 at 12:12 AM Greg Ewing wrote: > I'm wondering whether parens should be required when there are both > keyword args and more than one positional arg in an index. I.e instead > of > > a[1, 2, k = 3] > > you would have to write > > a[(1, 2), k = 3] > > That would make

[Python-ideas] Re: PEP 472 - new dunder attribute, to influence item access

2020-08-31 Thread Greg Ewing
On 31/08/20 4:23 pm, Guido van Rossum wrote: On Sun, Aug 30, 2020 at 2:43 AM Greg Ewing > wrote: On 30/08/20 7:45 pm, Guido van Rossum wrote: > I think we should say no to d[*args], because that will just become > d[(*args)], So maybe

[Python-ideas] Re: PEP 472 - new dunder attribute, to influence item access

2020-08-31 Thread Greg Ewing
On 31/08/20 4:11 pm, Guido van Rossum wrote: Can I write a.__getitem__((1, 2), k=3) and the function will see (i, j, k) == (1, 2, 3)? Yes. Okay, and if I write a.__getitem__((1, 3), k=2) will the function see the same thing? No, it will see (i, j, k) == (1, 3, 2). It's the same as if you

[Python-ideas] Re: PEP 472 - new dunder attribute, to influence item access

2020-08-31 Thread Greg Ewing
On 31/08/20 3:35 pm, Random832 wrote: x[(1,)] old arg=(1,); new args=((1,),)? > x[(1,2)] old arg=(1,2); new args=((1,2),)? No, I proposed *not* to do those -- putting parens around the arguments would continue to make no difference, regardless of which dunder was being called. Also, do we

[Python-ideas] Re: PEP 472 - new dunder attribute, to influence item access

2020-08-31 Thread Christopher Barker
On Sun, Aug 30, 2020 at 10:01 PM Random832 wrote: > > like `d[1,]` + keyword. > > perhaps, but I did have a thought after making that post. > > A new bytecode operation (we'll need one anyway, right?) which, in > addition to passing in the positionals and the keywords, also passes along > the