[Python-ideas] Total_order

2019-12-29 Thread David Mertz
In the IEEE total order, +0 and -0 are distinct, which your order doesn't handle, For NaNs, the issue is that NaN is NOT a single representation, but each combination of the sign bit and the 52 mantissa bits (except all zeros which signify infinity) when the exponent field is all ones is a differen

[Python-ideas] Re: Fix statistics.median()?

2019-12-29 Thread David Mertz
How is that fancy bitmask version different from my 3-line version? On Sun, Dec 29, 2019, 11:01 PM Tim Peters wrote: > [Richard Damon ] > > IEEE total_order puts NaN as bigger than infinity, and -NaN as less than > > -inf. > > > > One simple way to implement it is to convert the representaton to

[Python-ideas] Re: Fix statistics.median()?

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019 at 10:18 PM Richard Damon wrote: > IEEE total_order puts NaN as bigger than infinity, and -NaN as less than > -inf. > You mean like this? >>> def total_order(x): ... if math.isnan(x): ... return (math.copysign(1, x), x) ... return (0, x) ... ... >>> nums = [

[Python-ideas] Re: Fix statistics.median()?

2019-12-29 Thread David Mertz
"*Die ganzen Zahlen hat der liebe Gott gemacht, alles andere ist Menschenwerk*" ("God made the integers, all else is the work of man"). –Leopold Kronecker of course, Kronecker was wrong, and Cantor was right. But the quote is an excellent dis. :-) On Sun, Dec 29, 2019 at 9:41 PM Andrew Bar

[Python-ideas] Re: Fix statistics.median()?

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019, 9:23 PM Andrew Barnert > Here it is. I could save a line by not using the 'else'. > > def total_order(x): > if is_nan(x): > return (math.copysign(1, x), x) > else: > return (0, x) > > > This doesn’t give you IEEE total order. Under what circumstances w

[Python-ideas] Re: Fix statistics.median()?

2019-12-29 Thread David Mertz
rnert wrote: > On Dec 29, 2019, at 16:08, David Mertz wrote: > > > > * There is absolutely no need to lose any efficiency by making the > statistics functions more friendly. All we need is an optional parameter > whose spelling I've suggested as `on_nan` (but bikeshed

[Python-ideas] Re: Fix statistics.median()?

2019-12-29 Thread David Mertz
, 5, 7]) 4.0 """ data = sorted(data) n = len(data) if n == 0: raise StatisticsError("no median for empty data") if n%2 == 1: return data[n//2] else: i = n//2 return (data[i - 1] + data[i])/2 On Sun, Dec 29, 2019 a

[Python-ideas] Re: Fix statistics.median()?

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019 at 8:14 PM Andrew Barnert wrote: > On Dec 29, 2019, at 16:08, David Mertz wrote: > > > > * There is absolutely no need to lose any efficiency by making the > statistics functions more friendly. All we need is an optional parameter > whose spelling I&#x

[Python-ideas] Re: Fix statistics.median()?

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019 at 8:00 PM Richard Damon wrote: > Which is EXACTLY the reason I say that if this is important enough to > fix in median, it is important enough to fix in sorted. sorted gives > exactly the same nonsense result, it is only a bit more obvious because > it gives all the points.

[Python-ideas] Re: Fix statistics.median()?

2019-12-29 Thread David Mertz
Oh... I made a mistake in my off-the-cuff code. The items.append() shouldn't be in an else, but just in the loop. def median(it, on_nan=DEFAULT): if on_nan == 'unsafe': ... do all the current stuff ... elif on_nan == "ignore": return median((x for x in it if not is_nan(x)), on_nan='unsafe

[Python-ideas] Re: Fix statistics.median()?

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019 at 7:35 PM Andrew Barnert wrote: > On Dec 29, 2019, at 15:19, David Mertz wrote:On Sun, > Dec 29, 2019, 5:20 PM Andrew Barnert via Python-ideas > > But it is, out of all of the possible magma-over-magma structures on those >> values, the one that most cl

[Python-ideas] Re: Fix statistics.median()?

2019-12-29 Thread David Mertz
Several points: * NaN as missing-value is widely used outside the Python standard library. One could argue, somewhat reasonably, that Pandas and NumPy and PyTorch misinterpret the IEEE-754 intention here, but this is EVERYWHERE in numeric/scientific Python. We could DOCUMENT that None is a better

[Python-ideas] Re: Fix statistics.median()?

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019, 5:20 PM Andrew Barnert via Python-ideas > But it is, out of all of the possible magma-over-magma structures on those > values, the one that most closely approximates—in a well-defined and > useful, if very complicated, way—the rationals. I'm sort of convinced that Posits be

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019, 10:51 AM Steve Barnes wrote: > I do have to disagree here as it is entirely possible, in the world of > hardware interfacing, that an external hardware device could possibly > supply an sNaN as a something was seriously wrong flag, (as opposed to a I > haven't got any data

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019, 9:50 AM Steven D'Aprano wrote: > On Sun, Dec 29, 2019 at 08:22:49AM -0500, David Mertz wrote: > > Signalling NaN's are a pain because I'd want: > > > > is_nan(snan) == True > > > > But statistics.median([1, 2, snan], on_nan=&#

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-29 Thread David Mertz
function is_nonsignaling_nan(). On Sun, Dec 29, 2019, 7:25 AM Steven D'Aprano wrote: > On Sat, Dec 28, 2019 at 09:35:07PM -0800, Christopher Barker wrote: > > On Sat, Dec 28, 2019 at 3:40 PM David Mertz wrote: > > > > > What about Decimal snan? > > > > &

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread David Mertz
On Sun, Dec 29, 2019, 12:14 AM Richard Damon wrote: > But practicality beats purity, and practically, bit pattern CAN > represent numbers. If you want to argue that floats are not numbers, than > we can't use the statistics package, as we can't have any numbers to > perform the statistics on. >

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread David Mertz
On Sat, Dec 28, 2019, 11:02 PM Chris Angelico wrote: > They really truly ARE numbers. They are, in fact, these numbers: > > a = 3602879701896397 / 36028797018963968 > b = 3602879701896397 / 18014398509481984 > c = 5404319552844595 / 18014398509481984 > > When you perform addition on these, the re

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread David Mertz
On Sat, Dec 28, 2019 at 10:31 PM Richard Damon wrote: > Every value of the type float, except NaN and perhaps +inf and -inf > (depending on which version of the Real Number Line you use) IS actually > a representation of a Real Number (so I don't understand in what way you > can say they aren't "

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread David Mertz
On Sat, Dec 28, 2019, 9:36 PM Richard Damon wrote: > > NaN may be an instance of the abstract type Number, but is isn't a > mathematical number. Yes, floating point numbers are not pure-math Reals. Not even Rationals. They are a CS construct that is very useful for computer programs that very a

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread David Mertz
This is sophistry. NaN is an instance of the abstract type numbers.Number and the concrete type float. IEEE-754 defines NaN as collection of required values in any floating point type. I know the acronym suggests otherwise in a too-cute way, but NaN is archetypically a number in a computer science

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-28 Thread David Mertz
What about Decimal snan? On Sat, Dec 28, 2019, 5:53 PM Christopher Barker wrote: > On Sat, Dec 28, 2019 at 2:41 AM Antoine Pitrou > wrote: > >> +1 for a .is_nan() method on suitable types. That's the most natural >> and elegant solution, IMHO. Tricks like "x == x" are nice when you >> *know*

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-27 Thread David Mertz
h.isnan(torch_nans) ValueError: only one element tensors can be converted to Python scalars And yet: >>> np_nan_arr = np.array([np.nan]).reshape(1, 1, 1, 1) >>> math.isnan(np_nan_arr), np_nan_arr.shape (True, (1, 1, 1, 1)) So it's really only the 1-element-ness being chec

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-27 Thread David Mertz
Great work! I had not known if those corners. Have you tried with NumPy zero-D arrays or PyTorch Values? Both of those should have sensible answers. On Fri, Dec 27, 2019, 7:42 PM Steven D'Aprano wrote: > By the way, it's not as easy as you might think to test whether a value > is a NAN or not.

[Python-ideas] Re: Fix statistics.median()?

2019-12-27 Thread David Mertz
>>> nan1 is nan1 True The "in" operator might not do what you hope with NaNs. On Fri, Dec 27, 2019 at 2:15 PM Juancarlo Añez wrote: > The signature could be: > > def median(it, exclude=None): > > With *exclude* being a value, or collection supporting the *in*

[Python-ideas] Re: PEP 584 (dict merge operators), dict.update and dict.gapfill

2019-12-27 Thread David Mertz
On Fri, Dec 27, 2019, 12:05 PM Steven D'Aprano wrote: > On Fri, Dec 27, 2019 at 02:16:43PM +, Jonathan Fine wrote: > > Summary: dict.update(self, other) corresponds to 'merge-right'. Perhaps > add > > dict.gapfill(self, other), which corresponds to 'merge-left'. > I don't understand the conn

[Python-ideas] Re: Fix statistics.median()?

2019-12-26 Thread David Mertz
The behavior of your sort function is not any of the desirable options. Moving NaNs to the end is not the widely used Panda style of removing them; I cannot think of any situation where that behavior would be useful... even though I've read the Illiad. Other than wastefully creating an eager list,

[Python-ideas] Re: Fix statistics.median()?

2019-12-26 Thread David Mertz
NumPy does cannot really be done with a comprehension, so doing it in the function makes sense. Similar with raising an exception. On Thu, Dec 26, 2019, 9:35 PM Marco Sulla via Python-ideas < python-ideas@python.org> wrote: > David Mertz wrote: > > So we could get the Pandas-style b

[Python-ideas] Re: Fix statistics.median()?

2019-12-26 Thread David Mertz
arameter. But the default value of that parameter is indeed non-obvious. In a sort of Pandas way of using arguments, we might get `on_nan=["skip"|"poison"|"raise"|"random"]`. "Random" seems like the only wrong answer, but it is the

[Python-ideas] Re: Moving PEP 584 forward (dict + and += operators)

2019-12-26 Thread David Mertz
Really the point about partial order was EXACTLY the thread. If you want to say that floating point numbers are not ordered for exactly the same reason, and in exactly the same way, as sets... well, I guess you can die on that hill. Since NaN is an IEEE-854 value, everything you mention is precis

[Python-ideas] Re: Fix statistics.median()?

2019-12-26 Thread David Mertz
Oh... mine doesn't handle unbalanced duplicate values correctly :-). Maybe I'll figure out how to fix it. But I'm not really proposing the implementation anyway, just making the abstract point that we don't need sorted() On Thu, Dec 26, 2019 at 4:34 PM David Mertz wrote

[Python-ideas] Re: Fix statistics.median()?

2019-12-26 Thread David Mertz
s through to find the min or max though. I'm pretty sure that even in plain-Python, someone smarter than me, like Tim Peters (or others who watch here), could speed up my version by 2x. On Thu, Dec 26, 2019 at 4:13 PM David Mertz wrote: > Here is an implementation that: > > A. Only

[Python-ideas] Re: Fix statistics.median()?

2019-12-26 Thread David Mertz
On Thu, Dec 26, 2019 at 4:12 PM Richard Damon wrote: > As was pointed out, the statistics module specifically doesn't claim to > replace more powerful packages, like Numpy, so expecting it to handle > this level of nuance is beyond its specification. > Not being flat-out crazy in its answer isn'

[Python-ideas] Re: Fix statistics.median()?

2019-12-26 Thread David Mertz
Here is an implementation that: A. Only relies on '<' B. Has no special knowledge of NaN C. Does not use sorted() or .sort() for anything D. Is Pandas-like in choosing among only comparable items E. Only picks an element from the original iterator, does not take mean of two candidates (I.e. ki

[Python-ideas] Re: Fix statistics.median()?

2019-12-26 Thread David Mertz
Maybe we can just change the function signature: statistics.median(it, do_wrong_ass_thing_with_nans=False) :-) But yes, the problem is really with sorted(). However, the implementation of statistics.median() doesn't HAVE TO use sorted(), that's just one convenient way to do it. There IS NO righ

[Python-ideas] Re: Fix statistics.median()?

2019-12-26 Thread David Mertz
Well, *I* know the implementation. And I know about NaN being neither less than or greater than anything else (even itself). And I know the basic working of Timsort. But a lot of other folks, especially beginners or casual users, don't know all that. The do know that fractional numbers are a thin

[Python-ideas] Re: Fix statistics.median()?

2019-12-26 Thread David Mertz
those packages (or statsmodels, etc), not the standard library. But users of the standard library shouldn't get such peculiar behavior (even if it's not that hard to understand *why* it behaves as it does). On Thu, Dec 26, 2019 at 10:31 AM David Mertz wrote: > This came up in discussion h

[Python-ideas] Fix statistics.median()?

2019-12-26 Thread David Mertz
This came up in discussion here before, maybe a year ago, I think. There was a decision not to change the implementation, but that seemed like a mistake (and the discussion was about broader things). Anyway, I propose that the obviously broken version of `statistics.median()` be replaced with a b

[Python-ideas] Re: Moving PEP 584 forward (dict + and += operators)

2019-12-25 Thread David Mertz
On Wed, Dec 25, 2019, 9:11 PM python-ideas--- via Python-ideas < python-ideas@python.org> wrote: > On the contrary, on sets you can apply union *and* difference. And since > union seems the exact contrary of difference, it's illogical that | is used > instead of +. Set union is self-evidently NO

[Python-ideas] Re: Argumenting in favor of first()

2019-12-15 Thread David Mertz
On Sun, Dec 15, 2019, 2:21 PM Christopher Barker wrote: > On Sun, Dec 15, 2019 at 6:40 AM David Mertz wrote: > >> lines = get_lines_file_or_elswhere(resource) >> header = next(lines, sentinel) >> if looks_like_header(header): >> for line in lines: >>

[Python-ideas] Re: Argumenting in favor of first()

2019-12-15 Thread David Mertz
e in lines: ... On Sun, Dec 15, 2019, 5:40 AM Oscar Benjamin wrote: > On Sun, 15 Dec 2019 at 05:54, David Mertz wrote: > > > > A pattern I've written a number of times is roughly: > > > > lines = open(fname) > > header = next(lines) >

[Python-ideas] Re: Argumenting in favor of first()

2019-12-14 Thread David Mertz
A pattern I've written a number of times is roughly: lines = open(fname) header = next(lines) for line in lines: process (line, header) That's not so artificial, I think. Of course, first() would also work here. But I'm not sure it's any particular advantage in this case. On Sun, Dec 15, 201

[Python-ideas] Re: Segmentation of string

2019-12-14 Thread David Mertz
I had not known about math.comb() and math.perm() being added in 3.8. Those kinda feel to me like "not every one line function needs to be in the standard library." But I guess wiser people than me saw a reason they are needed. On Sat, Dec 14, 2019, 3:00 PM Tim Peters wrote: > Not really convolu

[Python-ideas] Re: Segmentation of string

2019-12-14 Thread David Mertz
18332-generator-for-integer-partitions/ Maybe Timmy will provide something more efficient than his partition code combined with itertools.permutation. I'm not sure if such shortcuts exist myself. On Sat, Dec 14, 2019, 10:41 AM David Mertz wrote: > This feels much too special purpose for a

[Python-ideas] Re: Segmentation of string

2019-12-14 Thread David Mertz
This feels much too special purpose for a string method, and probably for anything in the standard library. I'm not sure when someone would want this. But it's an only very sightly special case of integer composition ( https://en.wikipedia.org/wiki/Composition_(combinatorics)). And related to that

[Python-ideas] Re: Python slicing

2019-12-12 Thread David Mertz
We posted at same time. But the reason 0-D array isn't just a Python scalar is because it still has array attributes, most notably dtype. Now maybe 15 years ago NumPy could have created a bunch more custom numeric scalars for the different bit-lengths, but then we still wouldn't have the uniformit

[Python-ideas] Re: Python slicing

2019-12-12 Thread David Mertz
On Thu, Dec 12, 2019 at 7:39 PM Steven D'Aprano wrote: > Surely a zero-dimensional array ought to have no elements at all? > If you think of a 1-D array as falling on a line, and a 2-D array as occupying a region of a plane, then the equivalent of a geometric point is a 0-D array. It's not real

[Python-ideas] Re: Suggestion for language addition

2019-12-04 Thread David Mertz
Andrew Barnert via Python-ideas < python-ideas@python.org> wrote: > On Dec 4, 2019, at 12:14, Mike Miller wrote: > > > >  > >> On 2019-12-04 11:05, David Mertz wrote: > >> I've often wanted named loops. I know approaches to this have been > proposed

[Python-ideas] Re: Suggestion for language addition

2019-12-04 Thread David Mertz
9, at 21:28, Soni L. wrote: > > >> On 2019-12-04 5:12 p.m., Mike Miller wrote: > > >> > > >>> On 2019-12-04 11:05, David Mertz wrote: > > >>> I've often wanted named loops. I know approaches to this have been > proposed many times, and they all

[Python-ideas] Re: Suggestion for language addition

2019-12-04 Thread David Mertz
On Wed, Dec 4, 2019, 3:31 AM Jan Bakuwel wrote: > Ada even has "named loops", a really cool feature that allows you to exit > an outer loop inside an inner loop by "exiting" the loop referring to it's > name > While I am among the everybody not convinced by needing "end" constructs, I've often w

[Python-ideas] Re: Python should take a lesson from APL: Walrus operator not needed

2019-11-12 Thread David Mertz
Yeah. Maybe I should replace regex ' *:=' rather than just ':='. That's easy enough with the plugin On Tue, Nov 12, 2019, 12:12 PM Mike Miller wrote: > > On 2019-11-11 16:13, David Mertz wrote: > > I implemented this discussed arrow operator in vim with con

[Python-ideas] Re: Python should take a lesson from APL: Walrus operator not needed

2019-11-11 Thread David Mertz
I implemented this discussed arrow operator in vim with conceal plugin. This is an example given in PEP 572. It looks perfectly fine. It also does not require ANY change to Python-the-language. It just means that I can type ':' followed by '=' to get that, rather than type 'Alt+Shift', '2', '1',

[Python-ideas] Re: Python should take a lesson from APL: Walrus operator not needed

2019-11-10 Thread David Mertz
These thousands of words of repeating claims with weird non sequitur digressions seem to amount to "I wish Python used hard-to-enter unicode characters instead of words on normal keyboards" as far as I can tell because human brains, apparently, cannot make sense of the two character symbol `:=`

[Python-ideas] Re: Guidelines on ZWSP

2019-11-10 Thread David Mertz
Just my opinion, I do not think this belongs in PEP8 or official guidelines. Different editors will vary, of course, in how they handle "invisible" characters. But since various people will read your code, I think it's generally friendlier to use a name or Unicode escape rather than a quoted liter

[Python-ideas] Re: Python should take a lesson from APL: Walrus operator not needed

2019-11-06 Thread David Mertz
Unfortunately, my device dors not display LEFT ARROW WITH CIRCLED PLUS. Nor, obviously, write I have any way to enter it easily. On Wed, Nov 6, 2019, 2:05 PM Mike Miller wrote: > > On 2019-11-06 05:40, Andrew Barnert via Python-ideas wrote: > > While we’re at it, when you replace both = and := w

[Python-ideas] Re: Python 4000: Have stringlike objects provide sequence views rather than being sequences

2019-10-26 Thread David Mertz
internal representation is utf-16 or utf-32 if the string contains code points requiring multi-byte representation. On Sun, Oct 27, 2019, 12:19 AM Chris Angelico wrote: > On Sun, Oct 27, 2019 at 2:37 PM David Mertz wrote: > > What does actual CPython do currently to find that s[

[Python-ideas] Re: Python 4000: Have stringlike objects provide sequence views rather than being sequences

2019-10-26 Thread David Mertz
8 internal representation? On Sat, Oct 26, 2019, 11:02 PM Random832 wrote: > On Sat, Oct 26, 2019, at 20:26, David Mertz wrote: > > Absolutely, utf-8 is a wonderful encoding. And indeed, worst case is > > the same storage requirement as utf-16 or utf-32. For O(1) random > > a

[Python-ideas] Re: Python 4000: Have stringlike objects provide sequence views rather than being sequences

2019-10-26 Thread David Mertz
behavior. On Sat, Oct 26, 2019, 7:58 PM Steven D'Aprano wrote: > On Sat, Oct 26, 2019 at 07:38:19PM -0400, David Mertz wrote: > > On Sat, Oct 26, 2019, 7:29 PM Steven D'Aprano > > > > > > > (At worst, a code-point in UTF-8 takes three bytes, co

[Python-ideas] Re: Python 4000: Have stringlike objects provide sequence views rather than being sequences

2019-10-26 Thread David Mertz
On Sat, Oct 26, 2019, 7:29 PM Steven D'Aprano > (At worst, a code-point in UTF-8 takes three bytes, compared to four in > UTF-16 or UTF-32.) > http://www.fileformat.info/info/unicode/char/1/index.htm > ___ Python-ideas mailing list -- python-ideas

[Python-ideas] Re: Percent notation for array and string literals, similar to Perl, Ruby

2019-10-24 Thread David Mertz
On Thu, Oct 24, 2019, 9:01 AM Rhodri James > I think the strongest argument against both this proposal and the habit of > using split() is that everyone looking at your example string of colours, > including you and me, missed "forest green" the first time round. I noticed that. Is forest green

[Python-ideas] Re: Percent notation for array and string literals, similar to Perl, Ruby

2019-10-24 Thread David Mertz
On Thu, Oct 24, 2019, 7:19 AM Richard Damon wrote: > My one comment about this is to quote from PEP 20, the Zen of Python > > There should be one-- and preferably only one --obvious way to do it. > No problem, the new syntax doesn't risk being obvious! ;-) >

[Python-ideas] Re: Percent notation for array and string literals, similar to Perl, Ruby

2019-10-24 Thread David Mertz
For a while I used to use a Perl-inspired `q("red green blue")` as a shortcut. That's one character more than the proposed syntax, I leave the one line implementation to readers.[*] Despite saving some characters, it wasn't important enough to bother keeping in a utility module, let alone song as

[Python-ideas] Re: Percent notation for array and string literals, similar to Perl, Ruby

2019-10-23 Thread David Mertz
Is this the same code points identified by `str.isspace`? Thanks for doing that. I would have soon otherwise. Still, "most of them" isn't actually a precise answer for an uncertain string. :-) On Wed, Oct 23, 2019, 8:57 PM Christopher Barker wrote: > On Wed, Oct 23, 2019 at 5:53 PM Andrew Barne

[Python-ideas] Re: Percent notation for array and string literals, similar to Perl, Ruby

2019-10-23 Thread David Mertz
On Wed, Oct 23, 2019 at 7:17 PM David Mertz wrote: > Contains any of the following (non-escaped) characters. If they occur > inside quotes, it seems straightforward, but in this new '%w[]' thing, who > knows? > > U+00A0 NO-BREAK SPACE foo bar As a space, but often no

[Python-ideas] Re: Percent notation for array and string literals, similar to Perl, Ruby

2019-10-23 Thread David Mertz
On Wed, Oct 23, 2019, 4:31 PM Steven D'Aprano > David, you literally wrote the book on text processing in Python. I think > you are being disingenious here, and below when you describe a standard > string hex-escape \x20 that has been in Python forever and in just about > all C-like languages as "

[Python-ideas] Re: Percent notation for array and string literals, similar to Perl, Ruby

2019-10-23 Thread David Mertz
> > > > colors2 = "cyan forest green burnt umber".split() > > # oops, not what I wanted, quote each separately > > It isn't shared by the proposal. > > colors2 = %w[cyan forest green burnt\x20umber] > I don't get it. There is weird escaping of spaces that aren't split? That is confusing an

[Python-ideas] Re: Percent notation for array and string literals, similar to Perl, Ruby

2019-10-23 Thread David Mertz
One big problem with the current obvious way would be shared by the proposal. This hits me fairly often. colors1 = "red green blue".split() # happy Later colors2 = "cyan forest green burnt umber".split() # oops, not what I wanted, quote each separately On Wed, Oct 23, 2019, 7:03 AM Steven

[Python-ideas] Re: Percent notation for array and string literals, similar to Perl, Ruby

2019-10-22 Thread David Mertz
"one two three".split() On Tue, Oct 22, 2019, 3:56 PM Steve Jorgensen wrote: > See > https://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#The_%_Notation > for what Ruby offers. > > For me, the arrays are the most useful aspect. > > %w{one two three} > => ["one", "two", "three"]

[Python-ideas] Re: PEP 584: Add + and += operators to the built-in dict class.

2019-10-21 Thread David Mertz
On Mon, Oct 21, 2019, 9:14 AM Rhodri James > > The plus operation on two dictionaries feels far more natural as > a vectorised merge, were it to mean anything. E.g., I'd expect > > > {'a': 5, 'b': 4} + {'a': 3, 'b': 1} > > {'a': 8, 'b': 5} > > That's only a natural expectation if you also ex

[Python-ideas] Re: PEP 584: Add + and += operators to the built-in dict class.

2019-10-20 Thread David Mertz
On Sun, Oct 20, 2019, 6:09 PM Guido van Rossum > In the end I'm +0.5 on | and |=, +0 on + and +=, and -0 on doing nothing. > While my "vote" is and should be much less significant than Guido's, I've explained why my initial expectation for dict+dict would NOT be the proposed behavior, but rather

[Python-ideas] Re: PEP 584: Add + and += operators to the built-in dict class.

2019-10-19 Thread David Mertz
I am strong -1 on the proposal. The plus operation on two dictionaries feels far more natural as a vectorised merge, were it to mean anything. E.g., I'd expect >>> {'a': 5, 'b': 4} + {'a': 3, 'b': 1} {'a': 8, 'b': 5} However, the hypothetical behavior when different keys are present would not b

[Python-ideas] Re: Resolve append/add API inconsistency between set and list

2019-10-13 Thread David Mertz
I think the real code sample I located is pretty typical. Look at that other post. On Sun, Oct 13, 2019, 9:31 PM Steven D'Aprano wrote: > Let me see if I understand your workflow: > Well... "My workflow" is "Get a bunch of code that was written years before I was at my company, and enhance it o

[Python-ideas] Re: Resolve append/add API inconsistency between set and list

2019-10-13 Thread David Mertz
OK, quick search reveals some code in my actual codebase that illustrates the concept. This isn't code I was actually looking at this week, but it is in one of the company repos. def form_to_kwarg(form): """Converts the form into the kwarg used in creates and updates. If the form isn't v

[Python-ideas] Re: Resolve append/add API inconsistency between set and list

2019-10-13 Thread David Mertz
On Sun, Oct 13, 2019, 6:12 PM Andrew Barnert > from functools import singledispatch > @singledispatch > def just_add_it(collection, value): > raise TypeError(blah blah) > > Now you can explicitly register methods like this: > > just_add_it.register(set, set.add) > just_

[Python-ideas] Re: Resolve append/add API inconsistency between set and list

2019-10-13 Thread David Mertz
On Sun, Oct 13, 2019, 6:12 PM Steven D'Aprano: > Is that correct though? To the best of my memory, I've never wanted to add > an item to a list-or-set in 15 years, nor have I seen code in practice that > does so. I don't think it is "very common" Really?! I've seen it several times this week. Ma

[Python-ideas] Re: Resolve append/add API inconsistency between set and list

2019-10-13 Thread David Mertz
Obviously my silly name was a placeholder. I don't really have an opinion about the best spelling. On Sun, Oct 13, 2019, 6:02 PM Steve Jorgensen wrote: > David Mertz wrote: > > I have definitely hit this difficulty many times. The part of the code > that > > &quo

[Python-ideas] Re: Resolve append/add API inconsistency between set and list

2019-10-13 Thread David Mertz
I have definitely hit this difficulty many times. The part of the code that "just puts something in the collection" doesn't need to care conceptually about the kind of collection. Taking the data back out somewhere else more often needs to worry about order, efficiency, concurrency, etc. But as I

[Python-ideas] Re: Add Scalar to collections.abc with str, bytes, etc. being both Scalar and Sequence (therefore also Container)

2019-10-13 Thread David Mertz
What would be the practical use different from immutable? It seems like tuples and frozen sets are similarly often treated as "atomic", notwithstanding being iterable like strings are. On Sun, Oct 13, 2019, 5:07 PM Steve Jorgensen wrote: > This is a far more modest alternative to > https://mail.

[Python-ideas] Re: Allow with block (context manager) to return a value (e.g. to use as a builder)

2019-10-13 Thread David Mertz
Or if the context object needs different behavior, stick the "return value" in an attribute like restaurant_choices.data. On Sun, Oct 13, 2019, 2:56 PM David Mertz wrote: > Why not just: > > with build_choices('Restaurant') as restaurant_choices

[Python-ideas] Re: Allow with block (context manager) to return a value (e.g. to use as a builder)

2019-10-13 Thread David Mertz
Why not just: with build_choices('Restaurant') as restaurant_choices : ... print(restaurant_choices) On Sun, Oct 13, 2019, 2:49 PM Steve Jorgensen wrote: > Here's a more fleshed-out example of the kind of usage I have in mind. > Note that this does not require `with` to have an

[Python-ideas] Re: Additional meanings for "in" operator and ability to customize implementation

2019-10-13 Thread David Mertz
I would not want to overload plain strings' .__contains__() method to mean "has this substring OR matches this compiled regex." Besides being on a likely performance path, it's too special. And what about glob patterns, for example? Those too? But you can wrap your strings in RegexSearchableString

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-08 Thread David Mertz
> > x[foo=:] is x[foo=slice(None, None)] > We can combine this with the walrus operator for extra clarity: db[o0=o0:=o0==Oo:o0==oO] :-) Perl isn't dead, it's just resting. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe sen

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread David Mertz
It's really not a worthwhile win. It captures a tiny fraction of Pandas style filtering while complicating the syntax of Python. Here's another Pandas filter: db[db.x < 1] No help there with the next syntax. Here's another: db[(db.x == 1) | (db.y == 2)] A much better idea doesn't

[Python-ideas] Re: Automatic translation of Python to assembly language

2019-09-09 Thread David Mertz
It very much sounds like marketing hype to repeat this "direct to assembly" thing so much. Essentially it's claiming they are better at writing optimizers that are the more numerous authors of GCC, LLVM, etc. That's not inconceivable, but it's a hold claim requiring strong evidence. Thanks, Antoin

[Python-ideas] Re: Automatic translation of Python to assembly language

2019-09-08 Thread David Mertz
I read those two blog posts, and found very few technical details. On Sun, Sep 8, 2019, 1:30 PM Mark @pysoniq wrote: > Antoine, > > In response to "You should provide a detailed technical of your solution." > > The automatically created ctypes wrapper is one of the keys of the > project. Blog e

[Python-ideas] Re: Automatic translation of Python to assembly language

2019-09-08 Thread David Mertz
Also PyPy and Numba. Cython actually seems a bit different. Without annotations in a superset language, Cython programs mostly just use the same CPython runtime libraries. However, with a few type annotations sprinkled in (but not actual Python syntax), it can get big speedups). PyPy actually tri

[Python-ideas] Re: Automatic translation of Python to assembly language

2019-09-08 Thread David Mertz
I think the "proposal" is "people should give us money." :-) Yes, ads for commercial software do not belong on this list. On Sun, Sep 8, 2019, 12:08 PM Chris Angelico wrote: > On Sun, Sep 8, 2019 at 10:47 PM Mark @pysoniq wrote: > > > > Hello to the list, > > > > I have an idea for Python that

[Python-ideas] Re: PEP: Idiomatic API for shell scripting

2019-08-10 Thread David Mertz
; On Sat, Aug 10, 2019 at 6:53 AM David Mertz wrote: > >> Something very similar to this had been done many times in third party >> libraries. >> > > Check out Xonch for example: > > https://xon.sh/ > > -CHB > > > > >> None of those

[Python-ideas] Re: PEP: Idiomatic API for shell scripting

2019-08-10 Thread David Mertz
Something very similar to this had been done many times in third party libraries. None of those have become hugely popular, including none quite compelling me personally to do more than try them out as toys. It's too bad, in a way, since I love bash and use it all the time when it seems easier tha

[Python-ideas] Re: For-expression/throwaway comprehension

2019-08-04 Thread David Mertz
This sounds like a perfect opportunity to prove a third party module could be useful. I'm not sure how to configure tab completion callbacks in every environment like ipython, Jupyter, Python shell, PyCharm, VS Code, vim, or whatever. But without getting to that step (which is definitely possible

[Python-ideas] Re: For-expression/throwaway comprehension

2019-08-02 Thread David Mertz
There *is* also the '%load' magic. But 'from my_stuff import *' is almost always a better idea. On Fri, Aug 2, 2019, 2:49 PM Christopher Barker wrote: > Getting really OT now, but quickly: > > On Fri, Aug 2, 2019 at 11:28 AM Chris Angelico wrote: > >> On Sat, Aug 3, 2019 at 4:19 AM Ricky Teache

[Python-ideas] Coding environments

2019-08-02 Thread David Mertz
On Fri, Aug 2, 2019, 1:56 PM Chris Angelico wrote: > Also a bit old-school (it took me many years to learn the value of > syntax highlighting), and an educator, and I've seen students start > out with Jupyter. As an alternative to the vanilla REPL, I think it's > awesome if a little expensive on

[Python-ideas] Re: For-expression/throwaway comprehension

2019-08-02 Thread David Mertz
I'm definitely on the old side of the distribution of programmers, and I strongly appreciate tab expansion in tools like Jupyter and vim. I never used a full "IDE", whatever the boundary line is. But exactly that kind of reminder of e.g. "what's in itertools again?" is very helpful to me, both when

[Python-ideas] Re: Add a "partial with placeholders" function to the functools module

2019-07-27 Thread David Mertz
simply nicer to read for many cases. Sure this is a toy, but: >>> lastname = 'Mertz' >>> greet_david = partial(print, ..., 'David', lastname) # In Python 3.9 >>> greet_david('Verwelkoming') Verwelkoming David Mertz vs. >>> greet

[Python-ideas] Fwd: Adding where keyword inside list coprehensions

2019-07-15 Thread David Mertz
This comes up pretty often. Every example can be replaced by a loop over a single item list. It's a bit idiomatic, but not difficult. Many, as you note, can use the new walrus operator instead. [price for price in [item.get('price')] for item in basket if price is not None] On Mon, Jul 15, 201

[Python-ideas] Re: Coding using Unicode

2019-07-15 Thread David Mertz
It's easy, just use vim! (with conceal plugin). I haven't changed anything other than keywords and built-ins, but the plugin is happy to replace any other sequence or pattern. On Mon, Jul 15, 2019 at 9:26 AM Joao S. O. Bueno wrote: > Adrien - please take note that since you already wrote abo

[Python-ideas] Re: Sildenafil is the best medicine to cure ED issues

2019-07-06 Thread David Mertz
Seems useful, but it probably needs a PEP. :-) On Sat, Jul 6, 2019 at 12:27 AM John Brown wrote: > At the sensual mixing state, nitric oxide starts getting free from the > man's body that makes and spare cGMP in his hot organ. Finally, penile > muscles get broaden and speed of blood is augmented

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread David Mertz
ings are a bit different. This could be something such as using > something like a debugger tracing through some execution where you want to > record how the value was changed and where. > > On Thu, Jun 27, 2019 at 12:02 PM David Mertz wrote: > >> Obviously many kinds of

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread David Mertz
dmit that's a pretty easy way to be more explicit if it were added. On Thu, Jun 27, 2019, 11:56 AM Steven D'Aprano wrote: > On Thu, Jun 27, 2019 at 09:55:53AM -0400, David Mertz wrote: > > On Thu, Jun 27, 2019 at 9:13 AM Steven D'Aprano > wrote: > > > >

[Python-ideas] Re: A proposal (and implementation) to add assignment and LOAD overloading

2019-06-27 Thread David Mertz
uthor wrote something that was > hard to consume, it would be hard to consume. There are utilities available > to gaurd against unexpected code currently (isinstance), and I am proposing > the same. > > On Thu, Jun 27, 2019 at 9:58 AM David Mertz wrote: > >> On Thu, Jun 27

<    2   3   4   5   6   7   8   9   10   11   >