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
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
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
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
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
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
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
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
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
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,
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
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
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
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
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
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
16 matches
Mail list logo