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

2020-07-30 Thread Marco Sulla
On Thu, 30 Jul 2020 at 23:42, Steven D'Aprano wrote: > Of course anything is possible in theory, but I think that would require > shifting the existing keys and values in the array, and updating the > entries in the hash table to point to their key in the new position, and > probably other

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

2020-07-30 Thread Guido van Rossum
On Thu, Jul 30, 2020 at 22:23 Greg Ewing wrote: > On 31/07/20 4:04 am, Christopher Barker wrote: > > (Side note: why ARE the views provided by methods, rather than > > properties?) > > Probably because they construct objects, and are therefore > somewhat more expensive than is usually expected

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

2020-07-30 Thread Greg Ewing
On 31/07/20 4:04 am, Christopher Barker wrote: (Side note: why ARE the views provided by methods, rather than properties? Probably because they construct objects, and are therefore somewhat more expensive than is usually expected for an attribute access. -- Greg

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

2020-07-30 Thread Steven D'Aprano
On Thu, Jul 30, 2020 at 06:17:24PM -0400, Wes Turner wrote: > What new syntax do you propose? I don't propose new syntax. If this functionality is needed, regular method syntax will do the job without misleading people to th8ink that dicts are sequences that ought to support the full sequence

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

2020-07-30 Thread Wes Turner
What new syntax do you propose? On Thu, Jul 30, 2020 at 5:55 PM Steven D'Aprano wrote: > On Thu, Jul 30, 2020 at 05:03:58PM -0400, Wes Turner wrote: > > > Would these be the *non-mutating* methods desired of insertion-ordered > > dicts? > > > > .iloc[sli:ce] > > .iloc[int] > > .iloc[[list,]] >

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

2020-07-30 Thread Steven D'Aprano
On Thu, Jul 30, 2020 at 05:03:58PM -0400, Wes Turner wrote: > Would these be the *non-mutating* methods desired of insertion-ordered > dicts? > > .iloc[sli:ce] > .iloc[int] > .iloc[[list,]] > .iloc[callable] > .iloc[bitmask] > > .index(key) No. "iloc" sounds like a new Apple product to keep

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

2020-07-30 Thread Steven D'Aprano
On Thu, Jul 30, 2020 at 09:35:31PM +0200, Marco Sulla wrote: > On Thu, 30 Jul 2020 at 19:24, Steven D'Aprano wrote: > > > You can't insert a key in a specific position. If I have this dict: > > > > mydict = {'a': 1, 'c': 3, 'd': 4, 'e': 5} > > > > I can't insert 'b':2 between keys 'a' and

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

2020-07-30 Thread Wes Turner
Are you suggesting that dict views would become subscriptable? In [3]: %doctest_mode Exception reporting mode: Plain Doctest mode is: ON >>> x = dict(a=2, b=3, c=4) >>> x.items()[3] Traceback (most recent call last): File "", line 1, in x.items()[3] TypeError: 'dict_items' object is not

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

2020-07-30 Thread Wes Turner
On Thu, Jul 30, 2020, 3:37 PM Marco Sulla wrote: > On Thu, 30 Jul 2020 at 19:24, Steven D'Aprano wrote: > >> You can't insert a key in a specific position. If I have this dict: >> >> mydict = {'a': 1, 'c': 3, 'd': 4, 'e': 5} >> >> I can't insert 'b':2 between keys 'a' and 'c', except by

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

2020-07-30 Thread Marco Sulla
On Thu, 30 Jul 2020 at 19:24, Steven D'Aprano wrote: > You can't insert a key in a specific position. If I have this dict: > > mydict = {'a': 1, 'c': 3, 'd': 4, 'e': 5} > > I can't insert 'b':2 between keys 'a' and 'c', except by creating a new > dict. > Not sure about this. In C code,

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

2020-07-30 Thread Steven D'Aprano
On Thu, Jul 30, 2020 at 08:52:34AM -0700, Christopher Barker wrote: > The point being that dicts are now ordered, so maybe it makes sense to add > some operations that make it natural and easy to work with them in an > ordered way -- you know, like slicing :-) Dicts are not sequences and cannot

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

2020-07-30 Thread David Mertz
On Thu, Jul 30, 2020 at 11:55 AM Christopher Barker wrote: > > smaller_dict = dict(islice(large_dict.items(), 0, 255)) > well, beauty is in the eye of the beholder, of course. But really, you > think it's pretty to import itertools, then make a function call, for > what's very much a slicing

[Python-ideas] Re: How to prevent shared memory from being corrupted ?

2020-07-30 Thread Barry Scott
> On 30 Jul 2020, at 11:55, Vinay Sharma via Python-ideas > wrote: > > > >> On 28-Jul-2020, at 5:19 AM, Robert Collins > > wrote: >> >> On Mon, 27 Jul 2020 at 23:24, Vinay Sharma > > wrote: >>> >>> Hi, Thanks for replying.

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

2020-07-30 Thread Christopher Barker
On Wed, Jul 29, 2020 at 7:23 AM Wes Turner wrote: > .iloc[] is the Pandas function for accessing by integer-location: > > https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iloc.html > I'm not sure I quite get the analogy here, but ... >>> odict.iloc[3] > > > Would

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

2020-07-30 Thread Christopher Barker
On Tue, Jul 28, 2020 at 10:26 PM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > Christopher Barker writes: > > from itertools import islice > > > > smaller_dict = dict(islice(large_dict.items(), 0, 255)) > > > > which works, and isn't doing any unnecessary copying, but

[Python-ideas] Re: How to prevent shared memory from being corrupted ?

2020-07-30 Thread Vinay Sharma via Python-ideas
> On 28-Jul-2020, at 5:19 AM, Robert Collins wrote: > > On Mon, 27 Jul 2020 at 23:24, Vinay Sharma wrote: >> >> Hi, Thanks for replying. >> >>> One thing that is worth thinking about is the safety of the API that >>> is put together. A memory segment plus a separate detached semaphore >>>