[Python-ideas] Re: Python slicing

2019-12-12 Thread Michael Selik
On Thu, Dec 12, 2019 at 5:29 AM Siddharth Prajosh wrote: > Can we have an extra function for lists and string (and wherever slicing > works) to explicitly mention that we're slicing?? Something like - > *s=list(range(100)); > s.slice(10, 20).* > This exists already as ``itertools.islice`` and,

[Python-ideas] Re: Renaming json.load()

2019-11-27 Thread Michael Selik
Those functions, ``load`` and ``loads``, for better or worse, are a standard across many modules. Now that the standard has been established, it's good to stick with it. Good interface design needs to consider familiarity as well as what might be best without any history. On Wed, Nov 27, 2019 at

[Python-ideas] Re: Namespace context managers

2019-07-26 Thread Michael Selik
The class statement works in this fashion. foo = 1 class Bar: foo = 2 assert foo = 1 assert Bar.foo = 2 On Fri, Jul 26, 2019, 12:19 AM Batuhan Taskaya wrote: > I am proposing namespace context managers with implementing `__enter__` > and `__exit__` on dict objects. It would make closures

Re: [Python-ideas] Running average and stdev in the statistics module?

2019-05-06 Thread Michael Selik
I've often wanted a windowing function in itertools. One exists as a recipe in the docs. If I remember correctly, one reason this was never implemented is that the most efficient implementation changes depending on the size of the window. Use a deque(maxsize=n) for large windows and tuple

Re: [Python-ideas] singledispatch for methods

2019-03-26 Thread Michael Selik
On Tue, Mar 26, 2019, 1:09 PM Tim Mitchell wrote: > Is it time to add singledispatch for methods to the core library? > What's the motivation for it, beyond the fact that it's possible? Regarding jargon, aren't Python's instance methods are already single-dispatch, because they receive the

Re: [Python-ideas] Dict joining using + and +=

2019-02-27 Thread Michael Selik
On Wed, Feb 27, 2019 at 10:22 AM Anders Hovmöller wrote: > I dislike the asymmetry with sets: > > > {1} | {2} > {1, 2} > > To me it makes sense that if + works for dict then it should for set too. > > / Anders > > > On 27 Feb 2019, at 17:25, João Matos wrote: > > > > Hello, > > > > I would like

Re: [Python-ideas] Single line single expression try/except syntax

2019-01-27 Thread Michael Selik
Any discussion of except expressions should reference PEP 463 and respond to the arguments there. https://www.python.org/dev/peps/pep-0463/ On Sun, Jan 27, 2019, 3:52 AM Alex Shafer via Python-ideas < python-ideas@python.org wrote: > Hello, > > I'd like to discuss an idea I had to shorten the

Re: [Python-ideas] kwargs for return

2019-01-26 Thread Michael Selik
On Sat, Jan 26, 2019, 6:30 AM Anders Hovmöller > > I don't see anything here that can't be done by returning a dict, a > > namedtuple (possibly with optional fields), or some other object with > > named fields. They can be optional, they can have defaults, and you can > > extend the object by

Re: [Python-ideas] Potential PEP: with/except

2019-01-22 Thread Michael Selik
On Tue, Jan 22, 2019, 12:11 PM Paul Ferrell I see this as the natural evolution of what 'with' is all about - > replacing necessary try-finally blocks with something more elegant. We just > didn't include the 'except' portion. > The time machine strikes again. In fact, you can handle exceptions

Re: [Python-ideas] __len__() for map()

2018-11-26 Thread Michael Selik
If you know the input is sizeable, why not check its length instead of the map's? On Mon, Nov 26, 2018, 1:35 PM Kale Kundert I just ran into the following behavior, and found it surprising: > > >>> len(map(float, [1,2,3])) > TypeError: object of type 'map' has no len() > > I understand that

Re: [Python-ideas] Proposing additions to the standard library

2018-11-12 Thread Michael Selik
On Sat, Nov 10, 2018 at 6:56 PM Jonathan Crall wrote: > Sometimes there's a good, useful function than doesn't get added because >> there's no reasonable place to put it. For example, a "flatten" function >> has been talked about since Python 1.x days, and we still don't have a >> standard

Re: [Python-ideas] dict.setdefault_call(), or API variations thereupon

2018-11-02 Thread Michael Selik
On Fri, Nov 2, 2018 at 5:25 PM Anders Hovmöller wrote: > Could you explain what the difference is between defaultdicts "factory > which is unconditionally called when the key is missing" and "the default > is evaluated only on need"? > The distinction was the motivation for this thread:

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-02 Thread Michael Selik
On Fri, Nov 2, 2018 at 10:31 AM Philip Martin wrote: > [Why don't] csv writer and DictWriter provide ... > serialization/deserialization hooks? > Do you have a specific use-case in mind? My intuition is that comprehensions provide sufficient functionality such that changing the csv module

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Michael Selik
On Wed, Oct 31, 2018 at 12:31 PM Chris Angelico wrote: > What is being asked for here (if I'm not misreading) is a relatively simple > enhancement to a method on a built-in type (or a small handful of > types). If that garners reasonable support, the next step wouldn't be > a PEP, it'd just go

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Michael Selik
On Wed, Oct 31, 2018 at 10:17 AM Eric Fahlgren wrote: > On Wed, Oct 31, 2018 at 2:42 AM Chris Angelico wrote: > >> https://www.python.org/dev/peps/pep-0463/ wants to say hi. >> > > That was exactly my reaction, too, and usually is whenever one of these > "add a default" or similar ideas pops

Re: [Python-ideas] [Python-Dev] bpo-34837: Multiprocessing.Pool API Extension - Pass Data to Workers w/o Globals

2018-10-22 Thread Michael Selik
I switched this thread to the python-ideas list, since this is proposing a new feature. On Mon, Oct 22, 2018 at 12:13 PM Sean Harrington wrote: > I contend that multiprocessing.Pool is used most frequently with a single > task. I am proposing a feature that enforces this invariant, optimizes

Re: [Python-ideas] Revisiting Immutable Mappings

2018-10-10 Thread Michael Selik
How does a frozendict help in that example? It's not obvious to me. Despite not understanding that example, I'm +1 for having a frozendict. I don't think it'll increase cognitive load much, as it'll sit right next to frozenset when someone reads the builtins in alphabetical order. In my own

Re: [Python-ideas] Debugging: some problems and possible solutions

2018-10-03 Thread Michael Selik
On Wed, Oct 3, 2018 at 9:29 AM Anders Hovmöller wrote: >>> foo(=a, =1+bar) > >> Unfortunately, that won't help with Jonathan's inital example >> expression "big_array[5:20]" as it's not a valid keyword. > > I didn't understand that. The example you are referring to is > print('big_array[5:20] =',

Re: [Python-ideas] Suggestion: Extend integers to include iNaN

2018-09-29 Thread Michael Selik
On Fri, Sep 28, 2018 at 11:32 PM Steve Barnes wrote: > One of the strengths of the IEEE float, (to set against its many > weaknesses), is the presence of the magic value NaN. Not a Number, or > NaA, is especially useful in that it is a valid value in any > mathematical operation, (always

Re: [Python-ideas] "while:" for the loop

2018-09-26 Thread Michael Selik
On Wed, Sep 26, 2018, 9:42 AM Tobias Kohn wrote: > Although I doubt it will really make it into Python's grammar, I am all +1 > for the idea of having "repeat" as a loop keyword in Python. Actually, I > have been using "repeat" as a keyword in Python for quite some time now, > and found it not

Re: [Python-ideas] "while:" for the loop

2018-09-25 Thread Michael Selik
On Tue, Sep 25, 2018 at 8:46 PM Mikhail V wrote: > I suggest allowing "while:" syntax for the infinite loop. > I.e. instead of "while 1:" and "while True:" notations. > > My opinion: > 1. I think it'd definitely improve clarity. I prefer the explicit phrase, ``while True:``. Saying "while"

Re: [Python-ideas] Proposal for an inplace else (?=) operator

2018-09-22 Thread Michael Selik
On Sat, Sep 22, 2018 at 4:53 AM Lee Braiden wrote: > Problem: [Python] prevents actual default argument values being set in a > function signature > Feedback would be much appreciated. You'd be more convincing if you stated the problem more precisely. Python supports default values for function

Re: [Python-ideas] PEPs: Theory of operation

2018-09-22 Thread Michael Selik
On Sat, Sep 22, 2018 at 2:00 PM Stephen J. Turnbull wrote: > If one doesn't know who the senior developers are yet, she should > think twice about whether she's ready to PEP anything. On Sat, Sep 22, 2018 at 4:03 PM Anders Hovmöller wrote: > Is there a committee? Then why not just name it? >

Re: [Python-ideas] Asynchronous exception handling around with/try statement borders

2018-09-20 Thread Michael Selik
On Thu, Sep 20, 2018, 3:52 PM Kyle Lahnakoski wrote: > KeyboardInterrupt (any interrupt really) is dangerous. Now, we can > probably code a solution, but how about we remove the danger > The other day I accidentally fork-bombed myself with Python os.fork in an infinite loop. Whoops. It seems to

Re: [Python-ideas] Moving to another forum system where

2018-09-20 Thread Michael Selik
On Thu, Sep 20, 2018 at 10:25 AM Anders Hovmöller wrote: > >>> Not for drafting, but for submitting. > >> > >> Can you quote pep1? I think you’re wrong. > > > > I can't remember if I pulled this quote previously (that's one of the > > troubles with emails): "Following a discussion on

Re: [Python-ideas] Moving to another forum system where

2018-09-20 Thread Michael Selik
On Thu, Sep 20, 2018 at 9:27 AM Anders Hovmöller wrote: > >> That's because completion of discussion has never been a requirement > >> for writing a PEP. > > > > Not for drafting, but for submitting. > > Can you quote pep1? I think you’re wrong. I can't remember if I pulled this quote previously

Re: [Python-ideas] Moving to another forum system where

2018-09-20 Thread Michael Selik
On Thu, Sep 20, 2018 at 2:13 AM Stephen J. Turnbull wrote: > Michael Selik writes: > > > However, PEP 1 does not give instruction on how to evaluate whether > > that discussion has been completed satisfactorily. > > That's because completion of discussion has

Re: [Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

2018-09-14 Thread Michael Selik
On Fri, Sep 14, 2018 at 12:30 AM Anders Hovmöller wrote: > Since neither version fits well on one line or even three, I'd have > written each of those on a separate line, indented nicely to emphasize the > repetition. Seems fine to me. > > Sure. As would I. Doesn't change anything[.] > Our

Re: [Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

2018-09-14 Thread Michael Selik
On Fri, Sep 14, 2018, 12:17 AM Anders Hovmöller wrote: > > That's a bit of a dodge. There is a huge difference in verbosity between > > handler.new_file(field_name, file_name, content_type, content_length, > charset, content_type_extra) > > and > > handler.new_file(field_name=field_name,

Re: [Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

2018-09-14 Thread Michael Selik
On Thu, Sep 13, 2018, 11:58 PM Anders Hovmöller wrote: > In that case, you should be able to link to a compelling example. If you >> go to the trouble of finding one, I'll take time to try to refactor it. >> >> >> https://github.com/django/django/blob/master/django/db/models/sql/compiler.py#L707

Re: [Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

2018-09-14 Thread Michael Selik
On Thu, Sep 13, 2018, 11:48 PM Anders Hovmöller wrote: > > It's a bit too large for me to make sense of it quickly. My apologies for > not offering a holistic refactor. > > > My tool will print plenty of other examples. You can pick anyone really... > > > That’s positional because keyword is

Re: [Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

2018-09-13 Thread Michael Selik
On Thu, Sep 13, 2018 at 6:50 PM Anders Hovmöller wrote: > On 14 Sep 2018, at 03:35, Michael Selik wrote: > In that case, you should be able to link to a compelling example. If you > go to the trouble of finding one, I'll take time to try to refactor it. > > > https://github

Re: [Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

2018-09-13 Thread Michael Selik
On Thu, Sep 13, 2018 at 5:22 PM Anders Hovmöller wrote: > For example: > django-master/django/http/multipartparser.py 225 > Sorry, I didn't recognize this as a link on first read. I'll provide a link here to the code in context.

Re: [Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

2018-09-13 Thread Michael Selik
On Thu, Sep 13, 2018 at 5:34 PM Anders Hovmöller wrote: > I wrote a script so you can get a list of [good use cases] in big code > bases without looking through the code randomly. > https://gist.github.com/boxed/e60e3e19967385dc2c7f0de483723502 > In that case, you should be able to link to a

Re: [Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

2018-09-13 Thread Michael Selik
On Thu, Sep 13, 2018 at 11:35 AM Anders Hovmöller wrote: > Using keyword arguments is not painful. It's ugly in some unusual cases, > such as creating helper functions with nearly the same signature. > > It’s more painful than positional. To me the fact that everyone who works > on code bases

Re: [Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

2018-09-13 Thread Michael Selik
On Thu, Sep 13, 2018, 12:39 AM Anders Hovmöller wrote: > It seems to me this discussion has drifted away from the original > discussion toward one where you have a chain of functions with the same or > almost the same signature. This is interesting for sure but we shouldn’t > forget about the

Re: [Python-ideas] __iter__(), keys(), and the mapping protocol

2018-09-12 Thread Michael Selik
The dict keys method has other benefits beyond iteration. For example, it provides a set-like interface. On Wed, Sep 12, 2018, 10:50 PM Elias Tarhini wrote: > On Wed, Sep 12, 2018 at 4:42 PM Michael Selik wrote: > >> You want to have a Mapping that does not supply a keys meth

Re: [Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

2018-09-12 Thread Michael Selik
On Sat, Sep 8, 2018 at 4:17 AM Jonathan Fine wrote: > I thank Steve D'Aprano for pointing me to this real-life (although > perhaps extreme) code example > > > https://github.com/Tinche/aiofiles/blob/master/aiofiles/threadpool/__init__.py#L17-L37 It's hard to know from just a brief glance how

Re: [Python-ideas] __iter__(), keys(), and the mapping protocol

2018-09-12 Thread Michael Selik
Elias, I'm a little confused about what you're suggesting. You want to have a Mapping that does not supply a keys method? What use case motivated your proposal? On Mon, Sep 10, 2018, 7:04 PM Elias Tarhini wrote: > This has been bouncing around in my head for a while regarding the > requisite

Re: [Python-ideas] Keyword only argument on function call

2018-09-08 Thread Michael Selik
On Sat, Sep 8, 2018, 6:34 AM Anders Hovmöller wrote: > > A finer grained analysis tool would be helpful. I'm -0 on the idea > because I believe it would discourage more expressive names in calling > contexts in order to enable the proposed syntax. But I also see a big > difference between cases

Re: [Python-ideas] Keyword only argument on function call

2018-09-07 Thread Michael Selik
On Fri, Sep 7, 2018, 12:00 AM Jacco van Dorp wrote: > Sometimes we make a function only to be called once at a specific > location, more because of factoring out some functions for clarity. > I've found myself making the opposite refactoring recently, improving clarity by eliminating

Re: [Python-ideas] Why shouldn't Python be better at implementing Domain Specific Languages?

2018-08-31 Thread Michael Selik
On Thu, Aug 30, 2018, 9:23 PM David Mertz wrote: > On Fri, Aug 31, 2018, 12:08 AM Guido van Rossum wrote: > >> Hm. YAML is indeed a great, readable alternative to JSON or XML. But the >> term DSL implies (to me) more than just nested key-value pairs. (Though who >> knows maybe that's all Keras

Re: [Python-ideas] Why shouldn't Python be better at implementing Domain Specific Languages?

2018-08-30 Thread Michael Selik
On Thu, Aug 30, 2018 at 5:31 PM James Lu wrote: > It would be nice if there was a DSL for describing neural networks (Keras). > > model.add(Dense(units=64, activation='relu', input_dim=100)) > model.add(Dense(units=10, activation='softmax')) > > Why not JSON or XML for cross-language

Re: [Python-ideas] Off topic: 'strike a balance' - second language English

2018-08-18 Thread Michael Selik
On Sat, Aug 18, 2018 at 2:48 AM Steve Barnes wrote: > "The removal of technical terminology needs to be moderated to account > for the risk of loss of the essential meaning or the meaning being lost > due to excessive length. Where such terminology is widely accepted > within a given

Re: [Python-ideas] Does jargon make learning more difficult?

2018-08-15 Thread Michael Selik
On Wed, Aug 15, 2018, 12:06 AM Stefan Behnel wrote: > Michael Selik schrieb am 14.08.2018 um 21:42: > > This is supported by education research. Some light Googling found a > > study on the topic [0] that is consistent with my own observations. > > OTx2, and no offence, bu

Re: [Python-ideas] Does jargon make learning more difficult?

2018-08-14 Thread Michael Selik
The conversation about syntactic sugar for ``functools.partial`` led to a question about whether jargon like "lambda" makes the concept of an anonymous function more difficult to learn. In my own experience teaching, I find that many concepts are easier to introduce if I avoid the Python jargon

Re: [Python-ideas] Syntactic sugar to declare partial functions

2018-08-13 Thread Michael Selik
On Mon, Aug 13, 2018, 5:48 PM Greg Ewing wrote: > Chris Angelico wrote: > > No, lambda calculus isn't on par with brakes - but anonymous functions > > are, and if they're called "lambda", you just learn that. > > It's like saying that people would find it easier to learn to > drive if "brakes"

Re: [Python-ideas] Toxic forum

2018-08-13 Thread Michael Selik
Something that limits posts to once per day per thread could be useful, maybe even once per week. On Mon, Aug 13, 2018, 10:06 AM Michael Selik wrote: > > > On Mon, Aug 13, 2018, 5:59 AM Nicholas Chammas > wrote: > >> Maybe we need to revive that discussion? Overall,

Re: [Python-ideas] Toxic forum

2018-08-13 Thread Michael Selik
On Mon, Aug 13, 2018, 5:59 AM Nicholas Chammas wrote: > Maybe we need to revive that discussion? Overall, I don’t think we have a > people problem on this list as much as we have an administration tooling > problem. > +1 Even the fact that "straw poll" votes aren't counted automatically shows

Re: [Python-ideas] Python docs page: In what ways is None special

2018-07-26 Thread Michael Selik
On Mon, Jul 23, 2018 at 2:03 AM Jonathan Fine wrote: > Thank you for your attention. What have I missed? > None and a few other things are special-cased by CPython. The compiler won't bother to write bytecode instructions when an if-statement obviously evaluates false. That might surprise some

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Michael Selik
Sounds good to me. It'll make OrderedDict look much nicer at the REPL. On Thu, Jul 26, 2018 at 10:21 AM Terry Reedy wrote: > I am not sure what our repr change policy is, as there is a > back-compatibility issue but I remember there being changes. Given the way different Python prompts feel

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-22 Thread Michael Selik
On Sat, Jul 21, 2018, 6:55 PM Steven D'Aprano wrote: > On Sun, Jul 22, 2018 at 01:56:35AM +0200, Giampaolo Rodola' wrote: > > On Thu, Jul 19, 2018 at 3:39 PM Steven D'Aprano > wrote: > > > Tens of thousands of non-English speakers have had to learn the meaning > > > of what might as well be

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-19 Thread Michael Selik
On Thu, Jul 19, 2018 at 8:40 PM Michael Lee wrote: > >1. ... > >2. We can already easily get the same functionality using standard >Python. E.g., instead of doing foo?["bar"]?[0]?["baz"], we could do > lookup(foo, >"bar", 0, "baz") where lookup is a function that looks roughly

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-19 Thread Michael Selik
On Thu, Jul 19, 2018 at 5:29 PM Steve Dower wrote: > * "It makes it more complex" > * "It's harder to follow the flow" > > Depends on your measure of complexity. For me, I prioritise "area under > the indentation" as my preferred complexity metric (more lines*indents > == more complex), as well

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-19 Thread Michael Selik
On Thu, Jul 19, 2018 at 2:19 PM Terry Reedy wrote: > It seems to me that the problem is returning None. If functions raised errors instead of returning None, we wouldn't have so much trouble. Much of the benefit of PEP-572 was handling Nones and similar sentinel values. Instead of providing

Re: [Python-ideas] grouping / dict of lists

2018-07-13 Thread Michael Selik
On Mon, Jul 2, 2018 at 8:49 AM Chris Barker wrote: > On Fri, Jun 29, 2018 at 11:25 PM, Guido van Rossum > wrote: > > >> Hm, this actually feels heavier to me. But then again I never liked or >> understood the need for Counter -- >> > > actually, me neither -- and partly because it's too

Re: [Python-ideas] Fwd: grouping / dict of lists

2018-07-13 Thread Michael Selik
Thanks for linking to these. I looked at many of them in my own research, but for some reason didn't think to write down the links. I'll respond to each one separately. Throughout, I'm going to use my proposed ``grouped`` builtin to demonstrate possible revisions. Note that I am *not* suggesting

Re: [Python-ideas] Where should grouping() live (was: grouping / dict of lists)

2018-07-04 Thread Michael Selik
On Wed, Jul 4, 2018, 3:11 AM Ivan Levkivskyi wrote: > Replying to the question in subject, I think it would be better in > collections as a class. > Having it just as a function doesn't buy much, because one can do the > same with three lines and a defaultdict. > Four lines. You'll need to

Re: [Python-ideas] Fwd: grouping / dict of lists

2018-07-04 Thread Michael Selik
There are some cases when that's the correct behavior. It mimics pandas.DataFrame.groupby. For example, what if you have a sequence of (key, v1, v2) triples? Group by key, then keep the triples intact is the right choice sometimes. On Wed, Jul 4, 2018, 6:39 AM David Mertz wrote: > Steven: > >

Re: [Python-ideas] grouping / dict of lists

2018-07-03 Thread Michael Selik
On Tue, Jul 3, 2018, 6:32 PM Steven D'Aprano wrote: > On Tue, Jul 03, 2018 at 10:33:55AM -0700, Chris Barker wrote: > > On Tue, Jul 3, 2018 at 8:33 AM, Steven D'Aprano > wrote: > > > > > but why are we using key values by hand when grouping ought to do it > for > > >> us, as Michael Selik's

Re: [Python-ideas] Where should grouping() live (was: grouping / dict of lists)

2018-07-03 Thread Michael Selik
I'd prefer to simply write an example for the documentation or clarify the existing ones, then add good answers to StackOverflow questions. On Tue, Jul 3, 2018, 6:23 AM David Mertz wrote: > Guido said he has mooted this discussion, so it's probably not reaching > him. It took one thousand

Re: [Python-ideas] grouping / dict of lists

2018-07-02 Thread Michael Selik
ools use the equality function as the default. On Mon, Jul 2, 2018 at 3:48 AM Steven D'Aprano wrote: > On Mon, Jul 02, 2018 at 02:52:03AM -0700, Michael Selik wrote: > > Third, some classes might have a rich equality method that allows many > > interesting values to all wind up i

Re: [Python-ideas] grouping / dict of lists

2018-07-02 Thread Michael Selik
On Mon, Jul 2, 2018 at 2:52 AM Michael Selik wrote: > On Mon, Jul 2, 2018 at 2:32 AM Nicolas Rolin > wrote: > >> I think the current default quite weird, as it pretty much account to a >> count() of each key (which can be useful, but not really what I except from >>

Re: [Python-ideas] grouping / dict of lists

2018-07-02 Thread Michael Selik
On Mon, Jul 2, 2018 at 2:32 AM Nicolas Rolin wrote: > I think the current default quite weird, as it pretty much account to a > count() of each key (which can be useful, but not really what I except from > a grouping). I would prefer a default that might return an error to a > default that says

Re: [Python-ideas] grouping / dict of lists

2018-07-02 Thread Michael Selik
PM Michael Selik wrote: > >> On Fri, Jun 29, 2018 at 2:43 PM Guido van Rossum >> wrote: >> >>> On a quick skim I see nothing particularly objectionable or >>> controversial in your PEP, except I'm unclear why it needs to be a class >>> method on `d

Re: [Python-ideas] grouping / dict of lists

2018-06-29 Thread Michael Selik
to the GitHub repo, as per these comments. > On Fri, Jun 29, 2018 at 10:54 AM Michael Selik wrote: > >> Hello, >> >> I've drafted a PEP for an easier way to construct groups of elements from >> a sequence. https://github.com/selik/peps/blob/master/pep-.rst >&

Re: [Python-ideas] Fwd: Allow a group by operation for dict comprehension

2018-06-29 Thread Michael Selik
I created a separate thread to continue this discussion: "grouping / dict of lists" https://github.com/selik/peps/blob/master/pep-.rst In my proposal, the update offers a key-function in case the new elements don't follow the same pattern as the existing ones. I can understand the view that

Re: [Python-ideas] grouping / dict of lists

2018-06-29 Thread Michael Selik
that the majority appreciate it. Some are even able to guess what it does (would do) without any priming. Thanks for your time, -- Michael On Thu, Jun 28, 2018 at 8:38 AM Michael Selik wrote: > On Thu, Jun 28, 2018 at 8:25 AM Nicolas Rolin > wrote: > >> I use list and dict comp

Re: [Python-ideas] Allow a group by operation for dict comprehension

2018-06-28 Thread Michael Selik
On Thu, Jun 28, 2018, 6:46 PM Nicolas Rolin wrote: > The questions I should have asked In my original post was : > - Is splitting lists into sublists (by grouping elements) a high level > enough construction to be worthy of a nice integration in the comprehension > syntax ? > My intuition is

Re: [Python-ideas] Allow a group by operation for dict comprehension

2018-06-28 Thread Michael Selik
On Thu, Jun 28, 2018 at 5:12 PM Chris Barker via Python-ideas < python-ideas@python.org> wrote: > In [97]: student_school_list > Out[97]: > [('Fred', 'SchoolA'), > ('Bob', 'SchoolB'), > ('Mary', 'SchoolA'), > ('Jane', 'SchoolB'), > ('Nancy', 'SchoolC')] > > In [98]: result = defaultdict(list,

Re: [Python-ideas] Allow a group by operation for dict comprehension

2018-06-28 Thread Michael Selik
On Thu, Jun 28, 2018 at 4:34 PM Chris Barker via Python-ideas < python-ideas@python.org> wrote: > On Thu, Jun 28, 2018 at 4:23 PM, Greg Ewing > wrote: > >> Nicolas Rolin wrote: >> >>> student_by_school = {group_by(school): student for school, student >>> in student_school_list} >>> >> >> In

Re: [Python-ideas] Allow a group by operation for dict comprehension

2018-06-28 Thread Michael Selik
On Thu, Jun 28, 2018 at 8:25 AM Nicolas Rolin wrote: > I use list and dict comprehension a lot, and a problem I often have is to > do the equivalent of a group_by operation (to use sql terminology). > > For example if I have a list of tuples (student, school) and I want to > have the list of

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Michael Selik
On Wed, Jun 27, 2018 at 8:16 AM Franklin? Lee wrote: > On Wed, Jun 27, 2018, 10:31 Steven D'Aprano wrote: > >> On Wed, Jun 27, 2018 at 06:52:14AM -0700, Michael Selik wrote: >> > My intent was to ask where a range was in fact passed into max, not >> merely &

Re: [Python-ideas] Correct way for writing Python code without causing interpreter crashes due to parser stack overflow

2018-06-27 Thread Michael Selik
On Wed, Jun 27, 2018 at 12:04 AM Fiedler Roman wrote: > Context: we are conducting machine learning experiments that generate some > kind of nested decision trees. As the tree includes specific decision > elements (which require custom code to evaluate), we decided to store the > decision tree

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Michael Selik
On Wed, Jun 27, 2018 at 7:30 AM Steven D'Aprano wrote: > On Wed, Jun 27, 2018 at 06:52:14AM -0700, Michael Selik wrote: > > > > Have you ever written ``max(range(x))`` in production code? > > > I have never written that. > > > But I have written ``max(iterable)`

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Michael Selik
On Wed, Jun 27, 2018, 3:06 AM Steven D'Aprano wrote: > On Wed, Jun 27, 2018 at 12:36:12AM -0700, Michael Selik wrote: > > On Tue, Jun 26, 2018, 11:43 PM Jacco van Dorp > wrote: > > > > Generators dont have a __len__ method. And they might have min/max > > &g

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-19 Thread Michael Selik
Do you mind sharing an example usage in a realistic context? There might be a good solution that doesn't require adding magic methods. On Tue, Jun 19, 2018, 12:24 PM James Edwards wrote: > I've only recently looked for these special methods, so that in and of > itself may be the reason these

Re: [Python-ideas] Alternative spelling for list.append()

2018-06-18 Thread Michael Selik
On Mon, Jun 18, 2018, 6:59 PM Michael Selik wrote: > > if isinstance(v, ParseResults): > if v: > s = v.dump(indent, depth + 1) > else: > s = _ustr(v) > else: >

Re: [Python-ideas] Alternative spelling for list.append()

2018-06-18 Thread Michael Selik
On Mon, Jun 18, 2018 at 6:20 PM Juancarlo Añez wrote: > For all practical purpose, it would be enough to define that the >>> expression: >>> >>> mylist += [item] >>> >>> gets optimized to mylist.append(item). >>> >> >> Unfortunately, that would create yet another special case of operators >>

Re: [Python-ideas] Alternative spelling for list.append()

2018-06-18 Thread Michael Selik
On Mon, Jun 18, 2018 at 2:55 PM Mikhail V wrote: > On Mon, Jun 18, 2018 at 11:43 PM, Michael Selik wrote: > > On Mon, Jun 18, 2018 at 12:56 PM Mikhail V wrote: > >> Numpy arrays have also append() and insert() methods, > > In [2]: np.arange(1).append(2) > >

Re: [Python-ideas] Alternative spelling for list.append()

2018-06-18 Thread Michael Selik
On Mon, Jun 18, 2018 at 5:52 PM Juancarlo Añez wrote: > The idea is to introduce new syntax for the list.append() method. >> >> mylist[] = item >> > > For all practical purpose, it would be enough to define that the > expression: > > mylist += [item] > > gets optimized to

Re: [Python-ideas] Alternative spelling for list.append()

2018-06-18 Thread Michael Selik
On Mon, Jun 18, 2018 at 12:56 PM Mikhail V wrote: > Numpy arrays have also append() and insert() methods, > In [2]: np.arange(1).append(2) AttributeError: 'numpy.ndarray' object has no attribute 'append' In [3]: np.arange(1).insert AttributeError: 'numpy.ndarray' object has no attribute

Re: [Python-ideas] Alternative spelling for list.append()

2018-06-17 Thread Michael Selik
On Sun, Jun 17, 2018, 10:01 AM Mikhail V wrote: > The idea is to introduce new syntax for the list.append() method. > While you have summarized your proposal, you haven't included a summary of the criticism. Also, one thing that's very common for proposals to change syntax and create new uses

Re: [Python-ideas] Python Decorator Improvement Idea

2018-06-16 Thread Michael Selik
The idea of having a dunder to introspect the bound variable name has been discussed before. You can find the past discussions in the mailing list archive. If I recall correctly, there were very few use cases beyond namedtuple. With dataclasses available in 3.7, there may be even less interest

Re: [Python-ideas] Operator for inserting an element into a list

2018-06-16 Thread Michael Selik
On Sat, Jun 16, 2018, 10:22 AM Mikhail V wrote: > Plus it does not introduce overloading of the operator. Now you're critizing duck typing. And overloading has weakness in this - e.g. " var1 += var2 " does not > have mnemonics, other than + character (it could be two integers as well). >

Re: [Python-ideas] Operator for inserting an element into a list

2018-06-15 Thread Michael Selik
On Fri, Jun 15, 2018, 6:18 PM Mikhail V wrote: > On Sat, Jun 16, 2018 at 3:47 AM, Michael Selik wrote: > > > One of those links was discussing extend, not append. > > Yes and so what? ... What is different with append? Luckily for extend, it's similar to the "obvious

Re: [Python-ideas] Operator for inserting an element into a list

2018-06-15 Thread Michael Selik
On Fri, Jun 15, 2018, 5:24 PM Mikhail V wrote: > there is just nothing against append() method. > Then why break the Zen: there should be only one obvious way? But I see from various posts in the web and SO - people just want to spell > it compact, and keep the 'item' part clean of brackets.

Re: [Python-ideas] Operator for inserting an element into a list

2018-06-15 Thread Michael Selik
On Fri, Jun 15, 2018 at 10:25 AM Mikhail V wrote: > very uncommon to see standalone statements like: x.method() > Python has many such mutation methods. It sounds like you're judging the frequency of code patterns across all languages instead of just Python. Even then, I don't think that's

Re: [Python-ideas] Give regex operations more sugar

2018-06-15 Thread Michael Selik
On Thu, Jun 14, 2018, 11:22 PM Franklin? Lee wrote: > P.S.: Is there any way of guessing what proportion of Python programs > use `re`, either explicitly or implicitly? How many programs will, at > some point in their runtime, load the `re` module? > GitHub posts it's data to Google BigQuery.

Re: [Python-ideas] Operator for inserting an element into a list

2018-06-14 Thread Michael Selik
e statistics? On Thu, Jun 14, 2018, 7:40 PM Michael Selik wrote: > > > On Thu, Jun 14, 2018, 7:24 PM Mikhail V wrote: > >> what haven't we repeated in this thread yet? Motivation was explained. >> > > You have repeated your explanations a few times. It isn't convincing.

Re: [Python-ideas] Operator for inserting an element into a list

2018-06-14 Thread Michael Selik
On Thu, Jun 14, 2018, 7:24 PM Mikhail V wrote: > what haven't we repeated in this thread yet? Motivation was explained. > You have repeated your explanations a few times. It isn't convincing. It seems to me that your main complaint is that strings are iterable, though you haven't expressed it

Re: [Python-ideas] Operator for inserting an element into a list

2018-06-14 Thread Michael Selik
There's nothing wrong with your ideas if you were designing a language from scratch. However, Python has a long history and many tools and uses for the same operators you are considering. And even has a current "insert" operator (slice assignment). When adding a new feature, you need to consider

Re: [Python-ideas] Link accepted PEPs to their whatsnew section?

2018-06-12 Thread Michael Selik
Google will probably fix this problem for you after dataclasses become popular. The docs will gain a bunch of inbound links and the issue will (probably) solve itself as time passes. On Tue, Jun 12, 2018 at 2:48 PM Neil Schemenauer < nas-python-id...@arctrix.com> wrote: > I'm testing "Data

Re: [Python-ideas] Operator for inserting an element into a list

2018-06-12 Thread Michael Selik
On Tue, Jun 12, 2018 at 4:43 PM Mikhail V wrote: > inserting in the beginning of the list may be also not rare. > Inserting in the beginning of a list is *slow* and should be rare. If you want to append to the left-side of a list, you should use a deque. Check out ``collections.deque`` for your

Re: [Python-ideas] Operator for inserting an element into a list

2018-06-12 Thread Michael Selik
On Tue, Jun 12, 2018 at 11:08 AM Mikhail V wrote: > On Tue, Jun 12, 2018 at 7:42 PM, Clint Hepner > wrote: > > So the idea was about an insert/append operator. > Which would use augmented operator. The operator may be > /= or ^=. (I like ^= more, so I'll put here example with it). > The "/"

Re: [Python-ideas] Operator for inserting an element into a list

2018-06-12 Thread Michael Selik
That's a slice assignment, works great. I think if you use it more often you'll start to enjoy it. However, lists are optimized for append. Insert is slow. It should be discouraged, not encouraged by the language. If inserting is just a tad more awkward than appending, that's the language design

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Michael Selik
On Mon, Jun 11, 2018, 1:18 PM Chris Barker wrote: > On Mon, Jun 11, 2018 at 10:24 AM, Michael Selik wrote: > >> Would sind and cosd make Euler's formula work correctly? > > > There is nothing inherently more accurate in using degrees rather than > radians for trigonom

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Michael Selik
Whoops, it turns out Euler's formula does work! I expected imprecision, but at least one test matched. x = 42 cos(x) + 1j * sin(x) == e ** (1j * x) I suppose that's because it's radians. On Mon, Jun 11, 2018, 10:24 AM Michael Selik wrote: > Would sind and cosd make Euler's formula w

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Michael Selik
Would sind and cosd make Euler's formula work correctly? sind(x) + i * sind(x) == math.e ** (i * x) I suspect that adding these functions is kind of like those cartoons where the boat is springing leaks and the character tried to plug them with their fingers. Floating point is a leaky

Re: [Python-ideas] Trigonometry in degrees

2018-06-09 Thread Michael Selik
On Sat, Jun 9, 2018 at 2:22 AM Adam Bartoš wrote: > The idea was that the functions could handle the PiMultiple instances in a > special way and fall back to float only when a special value is not detected. > It would be like the proposed dsin functionality, but with a magic class > instead

  1   2   >