[Python-ideas] multidimensional lists

2020-07-08 Thread Hans Ginzel
Why not to allow tuple as a list index? T = [[11, 12, 5, 2], [15, 6, 10], [10, 8, 12, 5], [12, 15, 8, 6]] print(T[1][2]) 10 print(T[1, 2]) Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers or slices, not tuple https://stackoverflow.com/questio

[Python-ideas] Re: multidimensional lists

2020-07-08 Thread Chris Angelico
On Wed, Jul 8, 2020 at 11:18 PM Hans Ginzel wrote: > > Why not to allow tuple as a list index? > > >>> T = [[11, 12, 5, 2], [15, 6, 10], [10, 8, 12, 5], [12, 15, 8, 6]] > >>> print(T[1][2]) > 10 > >>> print(T[1, 2]) > Traceback (most recent call last): >File "", line 1, in > TypeError: list i

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

2020-07-08 Thread Stephen J. Turnbull
Jim Baker writes: > We should keep the most heavily accessed object type in Python as > lightweight as possible, and then build interesting structures around it, > just like we always do. +1 But we're not talking about the dict itself in this subthread. We're talking about views, and the imp

[Python-ideas] Re: multidimensional lists

2020-07-08 Thread Dominik Vilsmeier
On 08.07.20 15:09, Hans Ginzel wrote: Why not to allow tuple as a list index? T = [[11, 12, 5, 2], [15, 6, 10], [10, 8, 12, 5], [12, 15, 8, 6]] print(T[1][2]) 10 print(T[1, 2]) Traceback (most recent call last):   File "", line 1, in TypeError: list indices must be integers or slices, not

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

2020-07-08 Thread Jonathan Fine
Hi All This is related to discussion https://mail.python.org/archives/list/[email protected]/thread/KWAOQFSV3YJYQV2Y5JXGXFCXHJ3WFLRS/#ZT3OBOPNIMXQ2MU7N5RFBL5AJSYRZJ6Q In Python, lists don't have a join method. Instead, it's strings that have the join method. Hence we have: >>> ', '.join

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

2020-07-08 Thread David Mertz
This class or closure to clamp at specific bounds is nice. But I want to clamp based on runtime values for upper/lower fairly often. A function is much better for that use. On Wed, Jul 8, 2020, 11:22 AM Jonathan Fine wrote: > Hi All > > This is related to discussion > https://mail.python.org/arc

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

2020-07-08 Thread Steven D'Aprano
On Wed, Jul 08, 2020 at 04:19:32PM +0100, Jonathan Fine wrote: > For example, suppose we want limits on the room temperature, that the > thermostat cannot override. > >>> aircon_clipper = Clamper(50, 80) > > >>> thermostat_temp = 40 > >>> target_temp = aircon_temp_clipper(thermostat_t

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

2020-07-08 Thread Dominik Vilsmeier
On 08.07.20 17:19, Jonathan Fine wrote: Hi All This is related to discussion https://mail.python.org/archives/list/[email protected]/thread/KWAOQFSV3YJYQV2Y5JXGXFCXHJ3WFLRS/#ZT3OBOPNIMXQ2MU7N5RFBL5AJSYRZJ6Q In Python, lists don't have a join method. Instead, it's strings that have the jo

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

2020-07-08 Thread Christopher Barker
On Wed, Jul 8, 2020 at 8:37 AM David Mertz wrote: > This class or closure to clamp at specific bounds is nice. But I want to > clamp based on runtime values for upper/lower fairly often. A function is > much better for that use. > I suppose it comes down to whether you set the bounds once, and u

[Python-ideas] Re: multidimensional lists

2020-07-08 Thread Hans Ginzel
On Wed, Jul 08, 2020 at 11:32:32PM +1000, Chris Angelico wrote: >>> T = [[11, 12, 5, 2], [15, 6, 10], [10, 8, 12, 5], [12, 15, 8, 6]] >>> print(T[1, 2]) TypeError: list indices must be integers or slices, not tuple If you want a helper function, it's not hard to write it: def fetch(collection,

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

2020-07-08 Thread Stestagg
To add some numbers to this discussion. Using the patch I provided earlier, I tried running some performance comparisons against different call patterns & dictionary sizes: These tests have two versions: direct_index: uses the __getitem__ method in the patch (O(n)) on the view list_copy: convert

[Python-ideas] extending ast.parse with some lib2to3.pytree features

2020-07-08 Thread Peter Ludemann
With lib2to3 going away (https://bugs.python.org/issue40360), it seems to me that some of its functionality for handling "whitespace" can be fairly easily added to the ast module. (By "whitespace", I mean things like indent, dedent, comments, backslash; and also the ability to manipulate the encode

[Python-ideas] Re: Add __eq__ to colletions.abc.Sequence ?

2020-07-08 Thread Random832
On Mon, Jul 6, 2020, at 01:47, Neil Girdhar wrote: > Are all objects in Python equality-comparable? I know that you can > delete __hash__ to make an object unhashable (e.g., dicts). If so, this > is a great addition. Anyone can in principle override __eq__ to throw an exception, but they're not

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

2020-07-08 Thread William Pickard
CPython at the very least has 2 different type of native states: Interpreter & Module state. Unfortunately, the multi-phase initialization has a weakness when it comes to Module states. You can't access the module state without a pointer to the module. PyState_GetModule from a standpoint looks t

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

2020-07-08 Thread Inada Naoki
I think this comparison is unfair. > d.items()[0]vslist(d.items())[0] Should be compared with `next(iter(d.items())` > d.keys()[-1] vs list(d.keys())[-1] Should be compared with `next(reversed(d.keys()))`, or `next(reversed(d))`. > random.choice(d.items()) vsrandom.choic

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

2020-07-08 Thread Christopher Barker
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())` > why? the entire point of this idea is to have indexing syntax -- we can a