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

2020-07-09 Thread Inada Naoki
Oh, sorry. I read you did "random pick from dict", but I hadn't read you did "random pick and mutate dict" use case or not. On Fri, Jul 10, 2020 at 3:08 PM Chris Angelico wrote: > > On Fri, Jul 10, 2020 at 4:04 PM Inada Naoki wrote: > > > > On Fri, Jul 10, 2020 at 2:56 PM Chris Angelico wrote:

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

2020-07-09 Thread Chris Angelico
On Fri, Jul 10, 2020 at 4:04 PM Inada Naoki wrote: > > On Fri, Jul 10, 2020 at 2:56 PM Chris Angelico wrote: > > > > but it might be > > mutated in between. So the list would have to be reconstructed fresh > > every time. > > > > Do you think the use case is common enough to add a feature to buil

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

2020-07-09 Thread Inada Naoki
On Fri, Jul 10, 2020 at 2:56 PM Chris Angelico wrote: > > but it might be > mutated in between. So the list would have to be reconstructed fresh > every time. > Do you think the use case is common enough to add a feature to builtin type? I can not imagine. Anyway, if you want to benchmark that u

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

2020-07-09 Thread Chris Angelico
On Fri, Jul 10, 2020 at 3:41 PM Inada Naoki wrote: > > On Fri, Jul 10, 2020 at 1:53 PM Chris Angelico wrote: > > > > > > And immediately above that part, I said that I had made use of this, > > and had used it in Python by listifying the dict first. Okay, so I > > didn't actually dig up the code

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

2020-07-09 Thread Inada Naoki
On Fri, Jul 10, 2020 at 1:53 PM Chris Angelico wrote: > > > And immediately above that part, I said that I had made use of this, > and had used it in Python by listifying the dict first. Okay, so I > didn't actually dig up the code where I'd done this, but that's a use > case. I have *actually don

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

2020-07-09 Thread Chris Angelico
On Fri, Jul 10, 2020 at 7:20 AM Steven D'Aprano wrote: > > On Thu, Jul 09, 2020 at 10:25:46PM +1000, Chris Angelico wrote: > > > Getting a random element from a dict (not an arbitrary one but a > > random one) definitely does have a use-case. I've wanted it at times. > > Usually if I'm doing this

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

2020-07-09 Thread Christopher Barker
On Thu, Jul 9, 2020 at 10:29 AM Stestagg wrote: > The idea that there are future, unspecified changes to dicts() that may or > may not be hampered by allowing indexing sounds like FUD to me, unless > there are concrete references? > IIRC, first, dicts started preserving order as an implementatio

[Python-ideas] Re: Add builtin function for min(max())

2020-07-09 Thread Greg Ewing
On 10/07/20 8:05 am, Christopher Barker wrote: if not (withrdrawal_amount > balance):     give_cash_to_customer(withdrawal_amount) Unfortunately, with my luck they will have coded it as if withdrawal_amount <= balance: give_cash_to_customer(withdrawal_amount) But my bigger concern is th

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

2020-07-09 Thread Steven D'Aprano
On Thu, Jul 09, 2020 at 10:25:46PM +1000, Chris Angelico wrote: > Getting a random element from a dict (not an arbitrary one but a > random one) definitely does have a use-case. I've wanted it at times. > Usually if I'm doing this in Python, I just pay the price and build > the list, but as proof

[Python-ideas] Re: Python: Different native runtime state tiers.

2020-07-09 Thread Barry Scott
You might fine more interest on the Python C-API mailing list. https://mail.python.org/mailman3/lists/capi-sig.python.org/ Barry > On 8 Jul 2020, at 23:58, William Pickard wrote: > > CPython at the very least has 2 different type

[Python-ideas] Re: Add builtin function for min(max())

2020-07-09 Thread Ethan Furman
Operator chaining -- gotcha. Thanks Dominik and Ronald! -- ~Ethan~ ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Me

[Python-ideas] Re: Add builtin function for min(max())

2020-07-09 Thread Christopher Barker
Hmm, if my bank account balance is NaN, then: if not (withrdrawal_amount > balance): give_cash_to_customer(withdrawal_amount) would be pretty nice :-) -CHB On Thu, Jul 9, 2020 at 7:47 AM Eric Fahlgren wrote: > Yeah, but "not a number of pounds" sure beats seeing "£inf". > > On Thu, Jul 9

[Python-ideas] Re: Add builtin function for min(max())

2020-07-09 Thread Dominik Vilsmeier
On 09.07.20 21:04, Ethan Furman wrote: On 07/03/2020 05:03 PM, Steven D'Aprano wrote: def clamp(value, lower, upper): """Clamp value to the closed interval lower...upper. The limits lower and upper can be set to None to mean -∞ and +∞ respectively. """

[Python-ideas] Re: Add builtin function for min(max())

2020-07-09 Thread Ronald Oussoren via Python-ideas
> On 9 Jul 2020, at 21:04, Ethan Furman wrote: > > On 07/03/2020 05:03 PM, Steven D'Aprano wrote: > >> def clamp(value, lower, upper): >> """Clamp value to the closed interval lower...upper. >> The limits lower and upper can be set to None to >> mean -∞ and +∞ resp

[Python-ideas] Re: Add builtin function for min(max())

2020-07-09 Thread Ethan Furman
On 07/03/2020 05:03 PM, Steven D'Aprano wrote: def clamp(value, lower, upper): """Clamp value to the closed interval lower...upper. The limits lower and upper can be set to None to mean -∞ and +∞ respectively. """ if not (lower is None or upper

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

2020-07-09 Thread Stestagg
Re the benchmarks: yes, they're micro benchmarks, the intent was to show that the performance can be non impacting no, that doesn't invalidate them (just scopes their usefulness, my sales pitch at the end was slightly over-egging things but reasonable, imo), yes I ignored direct quadratic beh

[Python-ideas] Re: Add builtin function for min(max())

2020-07-09 Thread Eric Fahlgren
Yeah, but "not a number of pounds" sure beats seeing "£inf". On Thu, Jul 9, 2020 at 3:25 AM Jonathan Fine wrote: > Off topic: I saw this NaN article this morning. > > Title: Hungry? Please enjoy this delicious NaN, courtesy of British Gas > and Sainsbury's > URL: https://www.theregister.com/2020

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

2020-07-09 Thread Inada Naoki
On Thu, Jul 9, 2020 at 12:45 PM Christopher Barker wrote: > > On Wed, Jul 8, 2020 at 7:13 PM Inada Naoki wrote: >> >> I think this comparison is unfair. > > well, benchmarks always lie > >> > d.items()[0]vslist(d.items())[0] >> >> Should be compared with `next(iter(d.items())` > > wh

[Python-ideas] Re: An alternative to using a clamp / clip / trim function

2020-07-09 Thread Jonathan Fine
Hi Thank you all for the helpful comments. For me, the key question is as follows. There are two ways of asking for clamping, clipping or trimming (call it what you will). They are: aaa(lo, hi, num) bbb(lo, hi)(num) The question is then, which to provide? This is, in part, a syntactic qu

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

2020-07-09 Thread Dominik Vilsmeier
On 09.07.20 14:25, Chris Angelico wrote: On Thu, Jul 9, 2020 at 9:16 PM Steven D'Aprano wrote: Unless I have missed any others, we've only seen three use-cases: (a) The original post wanted a full sequence API for dictionaries, with the ability to insert keys at a specific index, not just get

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

2020-07-09 Thread Chris Angelico
On Thu, Jul 9, 2020 at 9:16 PM Steven D'Aprano wrote: > Unless I have missed any others, we've only seen three use-cases: > > (a) The original post wanted a full sequence API for dictionaries, with > the ability to insert keys at a specific index, not just get the N-th > key. Not going to happen.

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

2020-07-09 Thread Steven D'Aprano
On Wed, Jul 08, 2020 at 05:44:00PM +0100, Stestagg wrote: > So, use-case discussions aside, you get some pretty convincing performance > wins even on small-ish dictionaries if direct indexing is used. This reminds me of an anecdote my wife tells me about the days when she was in a band in the US

[Python-ideas] Re: Add builtin function for min(max())

2020-07-09 Thread Greg Ewing
On 9/07/20 10:25 pm, Jonathan Fine wrote: I particularly liked the Tideford Butterscotch Rice Pudding, at NaNp per 100g. I'd be a bit worried that if I bought one of those, I'd end up with a balance of NaN in my bank account. I hate to think what sort of havoc that would cause... -- Greg _

[Python-ideas] Re: Add builtin function for min(max())

2020-07-09 Thread Jonathan Fine
Off topic: I saw this NaN article this morning. Title: Hungry? Please enjoy this delicious NaN, courtesy of British Gas and Sainsbury's URL: https://www.theregister.com/2020/07/09/bork/ I particularly liked the Tideford Butterscotch Rice Pudding, at NaNp per 100g. -- Jonathan __