Re: [Python-ideas] Sorted lists

2019-04-08 Thread Terry Reedy
On 4/8/2019 4:48 PM, Barry Scott wrote: On 8 Apr 2019, at 19:37, Terry Reedy wrote: On 4/8/2019 5:40 AM, Steven D'Aprano wrote: On Mon, Apr 08, 2019 at 07:44:41AM +0100, Alex Chamberlain wrote: I think a better abstraction for a sorted list is a new class, which implements the Sequence pro

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Alex Chamberlain
On Mon, 8 Apr 2019 at 22:07, Barry Scott wrote: > > > > > On 8 Apr 2019, at 19:37, Terry Reedy wrote: > > > > On 4/8/2019 5:40 AM, Steven D'Aprano wrote: > >> On Mon, Apr 08, 2019 at 07:44:41AM +0100, Alex Chamberlain wrote: > >>> I think a better abstraction for a sorted list is a new class, whi

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Barry Scott
> On 8 Apr 2019, at 19:37, Terry Reedy wrote: > > On 4/8/2019 5:40 AM, Steven D'Aprano wrote: >> On Mon, Apr 08, 2019 at 07:44:41AM +0100, Alex Chamberlain wrote: >>> I think a better abstraction for a sorted list is a new class, which >>> implements the Sequence protocol (and hence can be use

Re: [Python-ideas] Built-in parsing library

2019-04-08 Thread Ai mu
@DavidMertz Each one of them takes a dramatically different approach to the defining a grammar they work more towards implementing well known standards like the BNF. well internally they might work different to parse etc. Abdur-Rahmaan Janhangeer Mauritius ___

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Terry Reedy
On 4/8/2019 5:40 AM, Steven D'Aprano wrote: On Mon, Apr 08, 2019 at 07:44:41AM +0100, Alex Chamberlain wrote: I think a better abstraction for a sorted list is a new class, which implements the Sequence protocol (and hence can be used in a lot of existing list contexts), but only exposed mutati

Re: [Python-ideas] Built-in parsing library

2019-04-08 Thread Christopher Barker
On Mon, Apr 8, 2019 at 12:02 AM Paul Moore wrote: > I would expect that the only reasonable way of getting a parsing > library in the stdlib would be to propose an established one from PyPI > to be moved into the stdlib Absolutely -- unlike some proposals, a stand-alone parsing lib could very e

Re: [Python-ideas] Sorted lists

2019-04-08 Thread David Mertz
On Mon, Apr 8, 2019, 6:26 AM Steven D'Aprano wrote: > Given all the points already raised, I think that an explicit SortedList > might be more appropriate. > This one looks cool. I've read about it, but haven't used it: http://www.grantjenks.com/docs/sortedcontainers/ I think a "sort hint" shou

Re: [Python-ideas] Sorted lists

2019-04-08 Thread David Mertz
On Mon, Apr 8, 2019, 5:46 AM Paul Moore wrote: > Still not convinced this is safe enough to be worth it ;-) > I'm convinced it's NOT safe enough to be worth it. On the other hand, a sortedlist subclass that maintained its invariant (probably remembering a key) sounds cool. I think there are one

Re: [Python-ideas] cli tool to print value, similar to pydoc

2019-04-08 Thread Thomas Gläßle
Steven D'Aprano wrote on 4/8/19 4:35 AM: > How will it know what object os is, without guessing, if you haven't > imported it? Like pydoc/help does it. I assume it splits by dots and imports the longest importable subsplit (try...except ImportError in a loop), then iteratively getattrs the rest

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Dan Sommers
On 4/8/19 6:25 AM, Steven D'Aprano wrote: > On Mon, Apr 08, 2019 at 02:55:54AM -0700, Nathaniel Smith wrote: >> If only we had some kind of API that could compute multiple quantiles at >> the same time... > > You mean something like this? > > quartiles, quintiles, deciles, percentiles = quan

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Paul Moore
On Mon, 8 Apr 2019 at 11:27, Steven D'Aprano wrote: > > Fair enough, but does it help you feel a bit better about the feature if > we called it a "sort hint", and emphasized that it should only be used > in the same sort of APIs where you might allow the caller to pass > > already_sorted=True

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Steven D'Aprano
On Mon, Apr 08, 2019 at 10:34:19AM +0100, Paul Moore wrote: > On Mon, 8 Apr 2019 at 10:10, Steven D'Aprano wrote: > > > Possibly the maintainer of bisect may decide that its not worth the > > change. But for the statistics module, I would certainly change the > > implementation of median() to loo

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Steven D'Aprano
On Mon, Apr 08, 2019 at 02:55:54AM -0700, Nathaniel Smith wrote: > Right, by "doesn't affect" I meant "cannot get any benefit, even if their > code is modified". Ah, sorry I misunderstood you. > > # This only makes sense if data is a sequence (list) > > # not an iterator. > > quarti

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Nathaniel Smith
On Mon, Apr 8, 2019, 02:09 Steven D'Aprano wrote: > On Sun, Apr 07, 2019 at 08:26:24PM -0700, Nathaniel Smith wrote: > > On Sun, Apr 7, 2019 at 7:37 PM Steven D'Aprano > wrote: > > > There are quite a few important algorithms which require lists to be > > > sorted. For example, the bisect module

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Paul Moore
On Mon, 8 Apr 2019 at 10:34, Steven D'Aprano wrote: > The median (and soon, quantiles) API says: > > I'm going to sort the list for you, whether you need it or > not, just in case you do. Hmm, I didn't see that mentioned in the docs. It makes a difference to my comment about behaviour cha

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Steven D'Aprano
On Mon, Apr 08, 2019 at 07:44:41AM +0100, Alex Chamberlain wrote: > I think a better abstraction for a sorted list is a new class, which > implements the Sequence protocol (and hence can be used in a lot of > existing list contexts), but only exposed mutation methods that can > guarantee that sort

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Paul Moore
On Mon, 8 Apr 2019 at 10:10, Steven D'Aprano wrote: > Possibly the maintainer of bisect may decide that its not worth the > change. But for the statistics module, I would certainly change the > implementation of median() to look something vaguely like this: > > # was > data = sorted(data)

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Steven D'Aprano
On Mon, Apr 08, 2019 at 03:18:53PM +1000, Cameron Simpson wrote: > If this is a publicly queriable value, is there any need to have a > dunder name at all? Why not just give lists a public is_sorted > attribute? I don't mind that. > I'm also not convinced the cost to every insert/append is wo

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Steven D'Aprano
On Mon, Apr 08, 2019 at 01:31:14PM +1000, Cameron Simpson wrote: > __setitem__ concerns me, along with other modification methods: what > about subclasses(*)? Every existing subclass which overrides __setitem__ > now needs to grow code to maintain __issorted__ if they do not > themselves call l

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Steven D'Aprano
On Sun, Apr 07, 2019 at 08:26:24PM -0700, Nathaniel Smith wrote: > On Sun, Apr 7, 2019 at 7:37 PM Steven D'Aprano wrote: > > There are quite a few important algorithms which require lists to be > > sorted. For example, the bisect module, and for statistics median and > > other quantiles. > > But

Re: [Python-ideas] cli tool to print value, similar to pydoc

2019-04-08 Thread Paul Moore
On Mon, 8 Apr 2019 at 08:30, Daniel Bradburn wrote: > > Could it be q that you are thinking about? Thanks, but no - that's debug output in your code. The tool I recall was much more like the OP's suggestion > foo sys.version 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AM

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Xavier Combelle
looks for me that means that all subclass of list has to maintain the __isorted__ invariant, looks like not a backward compatible modification and quite problematic in case of the invariant broken. So if I'm correct the design is brittle. Moreover, that solve only the strict subset of sort case w

Re: [Python-ideas] cli tool to print value, similar to pydoc

2019-04-08 Thread Daniel Bradburn
Could it be q that you are thinking about? Op ma 8 apr. 2019 om 09:10 schreef Paul Moore : > On Sun, 7 Apr 2019 at 12:44, Thomas Gläßle wrote: > > There is already a tool like this on PyPI [1] (sadly py2 only atm), but > > if you agree that this is a common pattern,

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Kirill Balunov
Basically, I like this idea and of course theoretically it has use cases. But in the proposed form, it feels strongly curtailed. In practice, what does it mean to be sorted? [('a', 1),('b', 2),('bb', 4),('aaa', 3)] # Is this list sorted? [('a', 1),('aaa', 3),('b', 2),('bb', 4)] # or this? [('a',

Re: [Python-ideas] cli tool to print value, similar to pydoc

2019-04-08 Thread Paul Moore
On Sun, 7 Apr 2019 at 12:44, Thomas Gläßle wrote: > There is already a tool like this on PyPI [1] (sadly py2 only atm), but > if you agree that this is a common pattern, I believe it would be a lot > more useful to have it in the stdlib. There's another tool on PyPI, I think, that does all you me

Re: [Python-ideas] Built-in parsing library

2019-04-08 Thread Paul Moore
On Mon, 8 Apr 2019 at 02:54, Nam Nguyen wrote: > Back to my original goal, I've gathered that there is some interest in having > a more general parser library in the stdlib. "Some", but not "much". Should I > start out with a straw proposal so that we can hash it out further? I would expect th