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

2019-12-10 Thread Andrew Barnert via Python-ideas
success. But I suspect this is exactly what you mean by “principles that work well in most of Python’s libraries”. Haskell doesn’t make you cabal install a hackage to get first. And likewise for Clojure, F#, Scala, etc. (Hell, when you npm install underscorejs, you don’t have to also go in

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

2019-12-11 Thread Andrew Barnert via Python-ideas
if it were called "one" instead of "first"? I’d expect one to be “like first, but raise if there are two or more elements”, because that’s what it means in a number of functional languages and database libraries, and more-itertools. ______

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

2019-12-11 Thread Andrew Barnert via Python-ideas
n’t think code that does that would be wrong or bad; using EAFP instead of LBYL is usually considered a good thing in Python. But also, most of the time, even when you aren’t testing for the error, you’re relying on it. The pairs and process functions above are only correct because of that T

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-11 Thread Andrew Barnert via Python-ideas
o, what else could you do? Make __setattr__ check the stack and see if it’s being called from type(self).__post_init__? Add an extra hidden attribute to every instance just to track whether you’re inside __post_init__ so __setattr__ can check it? ___

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-11 Thread Andrew Barnert via Python-ideas
e your fullname just by assigning to the always-mutable but private _fullname attribute, and have a readonly fullname property that uses that cache._______ Python-ideas mailing list -- [email protected] To unsubscribe send an email to python-i

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-11 Thread Andrew Barnert via Python-ideas
else could you do? Make __setattr__ check the stack and see if it’s >> being >> called from type(self).__post_init__? > Yes I think this is one possibility. I guess, but not a good one. Stack inspection is generally considered a huge code smell. For example, whenever someone on t

[Python-ideas] Re: Python slicing

2019-12-12 Thread Andrew Barnert via Python-ideas
On Dec 12, 2019, at 05:29, Siddharth Prajosh wrote: > > Python slicing looks really weird. How do I explain s=list(range(100)); > s[10:20] gives you a part of the list. Well, first you have to explain what “slicing” means, and that for lists it returns a new copy of the sub-list,

[Python-ideas] Re: Python slicing

2019-12-12 Thread Andrew Barnert via Python-ideas
re probably better off explicitly using index arrays and bool arrays as your indexes, as numpy does. ___ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.pytho

[Python-ideas] Re: Python slicing

2019-12-12 Thread Andrew Barnert via Python-ideas
a[1], and this case wouldn’t even have that potential for confusion. There are presumably historical reasons why it turned out this way, but if you were designing a new language that had tuple and slice and ellipsis indexing like current Python, would you expe

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

2019-12-12 Thread Andrew Barnert via Python-ideas
es into > itertools.) The docs for more_itertools.first say it’s equivalent to next of iter, which makes the behavior even more obvious to anyone who understands iteration in Python, even if they’ve never used itertools before. _______ Python-idea

[Python-ideas] Re: Python slicing

2019-12-12 Thread Andrew Barnert via Python-ideas
at, or anything else relevant) just because you changed subscripting. So t would be the first argument, the same as always. If you want 1 to be the first argument, you have to write MyWeirdTuple(*t). _______ Python-ideas mailing list -- python-ideas@pyt

[Python-ideas] Re: Python slicing

2019-12-12 Thread Andrew Barnert via Python-ideas
cond one, though, on reflection that would make perfect sense. Making the parser handling one or more colons instead of one or two colons shouldn’t be a problem. And it’s probably only because of historical reasons (Python used to have __getitem__(a) for [a] and __getslice__(a,b) for [a:b], and the

[Python-ideas] Re: Python slicing

2019-12-12 Thread Andrew Barnert via Python-ideas
ents. You can say all zero of the dimensions are any number you like, and you get that number to the zeroth power elements, which is always 1. _______ Python-ideas mailing list -- [email protected] To unsubscribe send an email to python-ideas-le...@py

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

2019-12-12 Thread Andrew Barnert via Python-ideas
On Dec 12, 2019, at 20:51, Tim Peters wrote: > > BTW, you can go a long way in Python without knowing anything about `iter()` > or `next()`. But not without mastering `for` loops. That's why I prefer to > say that, for ordinary cases, > > a = first(it) >

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

2019-12-12 Thread Andrew Barnert via Python-ideas
etely understandable to people who >> don’t >> know about iter, how can we put it in itertools, a module whose docs start >> off >> with a nice friendly introduction about the building blocks of an algebra for >> iterators that you can compose into powerful tools?

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

2019-12-14 Thread Andrew Barnert via Python-ideas
learn about iterators. There are certainly a lot of StackOverflow dups asking why `for line in file:` gives them no lines when just 10 lines earlier the same file had 20 lines. ___ Python-ideas mailing list -- [email protected] To unsubscribe send

[Python-ideas] Re: Add "elif" to "for_stmt" and "while_stmt"

2019-12-15 Thread Andrew Barnert via Python-ideas
ght be useful; maybe it’s even come up for me a few times. But if the motivating examples are cases where it would make the code less readable rather than more, that’s not a good sign. ___ Python-ideas mailing list -- [email protected] To unsu

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

2019-12-15 Thread Andrew Barnert via Python-ideas
t it Looking at my own REPL history and pile of throwaway scripts, dicts actually seem to make up a lot of my own uses of more_itertools.first. _______ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected]

[Python-ideas] Re: Add symlinks option at shutil.move parameters

2019-12-18 Thread Andrew Barnert via Python-ideas
r is. Does GNU or BSD mv provide an option for what you want? What’s your use case for wanting to do this? _______ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org

[Python-ideas] Re: "and if" and "or if" for trailing if statements - including explicit fallthrough

2019-12-21 Thread Andrew Barnert via Python-ideas
ust have some case where you really wanted this, that motivated you to propose it? _______ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas

[Python-ideas] Re: "and if" and "or if" for trailing if statements - including explicit fallthrough

2019-12-21 Thread Andrew Barnert via Python-ideas
lly reads the same. A fallthrough says “tail call does this stuff, and then does the stuff from the next (call) case”. An orif says “call, or also tail call which did some other stuff, does this stuff.” It seems backward to think of it that way. _______ Python-ideas

[Python-ideas] Re: Throw a TypeError exception if using type annotations (type hints) & the passed arg or return value is the wrong type

2019-12-24 Thread Andrew Barnert via Python-ideas
` If > this line is at the top of the file, then a TypeError is thrown on any > method/function that uses type hints in the current file if the passed arg or > return value is the wrong type. PHP’s feature doesn’t really make sense for Python. First, PHP is a weakly typed language; Pyt

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

2019-12-25 Thread Andrew Barnert via Python-ideas
On Dec 25, 2019, at 14:57, python-ideas--- via Python-ideas wrote: First, as a side note, you seem to have configured your python-ideas-posting address with the name “python-ideas” rather than with a name that can be used to distinguish you from other people. This will make conversations

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

2019-12-26 Thread Marco Sulla via Python-ideas
erent from addition), that you can't multiply a list > by an integer, that you can't multiply a string by an integer, that > you can't divide a string by a string, etc, etc, etc. Well, they are wrong :D They want funny and lazy operators? Suggest them numpy. numpy transform P

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

2019-12-26 Thread Marco Sulla via Python-ideas
xt, or just that you don't see value in it? > If you're just presenting your opinion, then present it as an opinion, > not as a scoffing dismissal. Angelico, I can change my mind if you will be able to give me at least one practical example where `sorted(sets)` is really useful

[Python-ideas] Re: AVG Function as Built-in

2019-12-26 Thread Marco Sulla via Python-ideas
So why only mean and not median, that's better for statistics? :D Seriously, if you want it builtin, add it to PYTHONSTARTUP: https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSTARTUP from statistics import mean ___ Python-ideas ma

[Python-ideas] Re: AVG Function as Built-in

2019-12-26 Thread Marco Sulla via Python-ideas
Stephen J. Turnbull wrote: > > from statistics import mean > > sum([1e16,1,1])/3 == 1e16/3# surprise! > > True > > mean([1e16,1,1]) == 1e16/3 > > False > > Regards, Python 3.9.0a0 (heads/master-dirty:d8ca2354ed, Oct 30 2019, 20:25:01) [GCC 9.2.1 201909

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

2019-12-26 Thread Marco Sulla via Python-ideas
.and? ___ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@py

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

2019-12-26 Thread Marco Sulla via Python-ideas
e of the two central values is NaN, the other value is returned. The function returns NaN only if both are NaNs. _______ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.py

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

2019-12-26 Thread Andrew Barnert via Python-ideas
> On Dec 26, 2019, at 04:15, Marco Sulla via Python-ideas > wrote: > > Mathematically, Whenever someone tries to argue that “Mathematically, this doesn’t make sense” it ends up isomorphic to an argument that they really would have enjoyed one more semester of math classes as an u

[Python-ideas] Re: AVG Function as Built-in

2019-12-26 Thread Andrew Barnert via Python-ideas
’t need anything else from stats (or numpy). Whatever. But you have to make that argument; otherwise, stats.mean seems like the right place for it, just like functools.partial and math.sin. _______ Python-ideas mailing list -- [email protected] T

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

2019-12-26 Thread Andrew Barnert via Python-ideas
easily just from math itself. Or, once you can get infinite values, you can easily get nan values with just basic arithmetic: >>> 1e1000 - 1e1000 nan _______ Python-ideas mailing list -- [email protected] To unsubscribe s

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

2019-12-26 Thread Marco Sulla via Python-ideas
ways spell the > operation <. Nope. Usually, you define the operation <=. And posets requires that set1 <= set1 == True and this is true. Unluckily, sort operations in Python requires and uses **only** `__lt__()`. And set1 < set1 == False So, **in Python**, sorting a list of se

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

2019-12-26 Thread Marco Sulla via Python-ideas
the biased median_high() and median_low() functions of `statistics`. ___ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.o

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

2019-12-26 Thread Andrew Barnert via Python-ideas
ed to intentionally look like < well over a century before Python, but for the sake of accuracy: Gergonne was using C (from the French or Latin word for containment) for superset as early as 1817. But most people didn’t follow him, and in fact < and > was the most popular spelling

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

2019-12-26 Thread Marco Sulla via Python-ideas
lice the NaNs away more easily, if (s)he wants :) I think Java do the things this way, because I tested `Collections.sort()` with a List and it puts all NaNs at the end of the list. ___ Python-ideas mailing list -- [email protected] To unsubscribe

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

2019-12-26 Thread Marco Sulla via Python-ideas
could at least separate this discussion in a separate thread. Can you, please? Thanks in advance. ___ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/

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

2019-12-26 Thread Andrew Barnert via Python-ideas
> On Dec 26, 2019, at 11:32, Marco Sulla via Python-ideas > wrote: > > Andrew Barnert wrote: >>> the operator is ⊂. "<" operator is used for >>> comparison, and it's vital for sorting. >> Yes. It’s the defining operation for the partial

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

2019-12-26 Thread Marco Sulla via Python-ideas
Andrew Barnert wrote: > I didn’t want to get into that, because I assumed you weren’t going to argue > that > <= makes sense for sets but < doesn’t So you're telling about **strict** partial ordering. I can spend thousand of words, but I think Python can speak for me: `

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

2019-12-26 Thread Marco Sulla via Python-ideas
David Mertz wrote: > Here is an implementation that: > A. Only relies on '<' Well, no. There's an `==` check. Can you please read this 2 posts of mine? https://mail.python.org/archives/list/[email protected]/message/7255SH6LSC266HAGI4SRJGV4JTUMMI4J/ https://mail.

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

2019-12-26 Thread Andrew Barnert via Python-ideas
On Dec 26, 2019, at 12:19, Marco Sulla via Python-ideas wrote: > > IMHO, another sorted function, slower than it, should be added. You can very easily just write a key function that does this for you. In fact, you can write different key functions for different variations. For examp

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

2019-12-26 Thread Andrew Barnert via Python-ideas
On Dec 26, 2019, at 12:36, Richard Damon wrote: > > On 12/26/19 2:10 PM, Andrew Barnert via Python-ideas wrote: >>> On Dec 26, 2019, at 10:58, Richard Damon wrote: >>> Note, that NaN values are somewhat rare in most programs, I think they can >>> only come ab

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

2019-12-26 Thread Andrew Barnert via Python-ideas
On Dec 26, 2019, at 14:13, Chris Angelico wrote: > > On Fri, Dec 27, 2019 at 9:07 AM Andrew Barnert via Python-ideas > wrote: >> >> You can very easily just write a key function that does this for you. In >> fact, you can write different key functions for diffe

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

2019-12-26 Thread Marco Sulla via Python-ideas
a comparison between two floats. So they take the most practical solution: return false. But Python and high level languages have another option: raise an exception. And this is IMHO the most sane solution, because you **can't** compare NaNs. Think about a list with a NaN inside. Ok, now the s

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

2019-12-26 Thread Marco Sulla via Python-ideas
Andrew Barnert wrote: > On Dec 26, 2019, at 12:19, Marco Sulla via Python-ideas > [email protected] wrote: > you can get the behavior of your algorithm below: > @functools.cmp_to_key > def flip_incomparables_key(a, b): > if a < b: return -1 > if b <

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

2019-12-26 Thread Andrew Barnert via Python-ideas
> On Dec 26, 2019, at 14:46, Marco Sulla via Python-ideas > wrote: > > David Mertz wrote: >> NaN is an IEEE-854 value, everything you >> mention is precisely identical of floats. >> Is your argument that we need to stop using the '<' operator f

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

2019-12-26 Thread Andrew Barnert via Python-ideas
On Dec 26, 2019, at 15:27, Marco Sulla via Python-ideas wrote: > > Andrew Barnert wrote: >> On Dec 26, 2019, at 12:19, Marco Sulla via Python-ideas >> [email protected] wrote: >> you can get the behavior of your algorithm below: >> @functools.cmp_to_key &

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

2019-12-26 Thread Marco Sulla via Python-ideas
= float("nan") print(sorted([x, 6, -10, float("-inf"), 1981, 8, y, float("+inf"), 19, 23], key=iliadSort)) ``` result: ``` [-inf, -10, 6, 8, 19, 23, 1981, inf, nan, nan] ``` but works only for NaNs and requires also "=="... 0_____o ____

[Python-ideas] `set` API and various sorting problems

2019-12-26 Thread Marco Sulla via Python-ideas
Andrew Barnert wrote: > if you’re going to be a pedant, the floats in > whatever Python you’re using right now are probably 854/754-1985 doubles, not > 754-2019 > binary64s. Mr. Andrew Barnet, if pedant means adhere to the standard, yes, I'm a pedant. > > This is because

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

2019-12-26 Thread Marco Sulla via Python-ideas
iliadSort(a, b): if a < b: res = -1 elif not b == b: res = -1 else: res = 0 return res and NaNs are moved at the end of the list. ___________ Python-ideas mailing list -- [email protected] To unsubscribe s

[Python-ideas] Alternative to `enumerate` and `range(len(sequence))`: indexes() and entries()

2019-12-26 Thread Marco Sulla via Python-ideas
same for entries(). It should be: 1. a SequenceEntriesView 2. a generator that yields the tuples (index, value) What do you think about? ___ Python-ideas mailing list -- [email protected] To unsubscribe send an email to python-ideas-le...@pytho

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

2019-12-26 Thread Marco Sulla via Python-ideas
If the NaNs are not really member of your population, it's ok. On the contrary, if you use my median function with the key function I posted before, you have not this problem. The iterable is sorted well and you get the real median. _______ Pyth

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

2019-12-26 Thread Marco Sulla via Python-ideas
Oh my... Mertz, listen to me, you don't need a parameter. You only need a key function to pass to `sorted()` If you use this key function: https://mail.python.org/archives/list/[email protected]/message/M3DEOZLA63Z5OIF6H6ZCEXK36GQMLVVA/ in my median() function: https://mail.pytho

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

2019-12-26 Thread Marco Sulla via Python-ideas
ue to use the iterable to access the rest of the iterable. `first()` creates an iterator, uses it and throw it away. What a waste! Greta Thunberg is very angry with you all :D So 200 posts for one line less? I really don't catch the point. _______ Py

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

2019-12-26 Thread Marco Sulla via Python-ideas
. Non-experts probably does not even know what to pass to that parameter. Non-experts can also read the docs, you know?!? Anyway, I'm not here to convince you of anything. Continue to use Pandas, the most slow module in the history of Python, that my company asked to me to remove to all

[Python-ideas] Re: `set` API and various sorting problems

2019-12-27 Thread Marco Sulla via Python-ideas
Steven, can you please remember me what operations can return NaN? I remember for example 0/0 and +Infinity - +Infinity. ___ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https

[Python-ideas] Re: Alternative to `enumerate` and `range(len(sequence))`: indexes() and entries()

2019-12-27 Thread Marco Sulla via Python-ideas
Steven D'Aprano wrote: > On Fri, Dec 27, 2019 at 02:22:48AM -, Marco Sulla via Python-ideas wrote: > > It's very common to see: > > for i, x in enumerate(sequence): > > [...] > > > > Yes, that is very common, except that "sequence" ca

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

2019-12-27 Thread Marco Sulla via Python-ideas
Excuse me Mr. Fine, can't you simply do `d2.update(c2)`??? ___ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Me

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

2019-12-27 Thread Marco Sulla via Python-ideas
Eric Fahlgren wrote: > You apparently did not read the posts, because the point was whether it > raises or returns a default value, not whether it saves one line or ten. You apparently don't know Python: ``` next(iterator) # raises an exception if no more elements next(iterator

[Python-ideas] Re: findfirst() from findalliter(), and first

2019-12-27 Thread Andrew Barnert via Python-ideas
That’s also a great argument that it should be added to the re module, so people don’t have to try to figure out how to port C code to Python and then test the hell out of it just to get something that’s only missing in the first place for historical/naming reasons. _____

[Python-ideas] Re: findfirst() from findalliter(), and first

2019-12-28 Thread Andrew Barnert via Python-ideas
suite with wide coverage that you could adapt to compare list(findalliter) vs. findall or something? _______ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at

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

2019-12-28 Thread Andrew Barnert via Python-ideas
es, not a fully general one. ___ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/pyth

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

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 28, 2019, at 23:29, Steve Barnes wrote: > >  > From: Andrew Barnert > Sent: 28 December 2019 20:21 > To: Steve Barnes > Cc: Christopher Barker ; [email protected]; python-ideas > > Subject: Re: [Python-ideas] Re: Testing for NANs [was Re: Fix > statistics

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

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 04:34, Steven D'Aprano wrote: > > On Sat, Dec 28, 2019 at 11:58:35PM -0800, Andrew Barnert via Python-ideas > wrote: > >> No it won’t, unless you assume here that no possible non-numeric types >> could ever have non-self-equal values. Which is

[Python-ideas] Re: The "When" Keyword

2019-12-29 Thread Andrew Barnert via Python-ideas
omes true, notify a condition variable…). I think I wrote a facetious post on my old Stupid Python Ideas blog on all the control flow statements Python is “missing” and included a when for this purpose. I don’t think the advantage is anywhere near worth the cost. Being explicit about whic

[Python-ideas] Re: The "When" Keyword

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 12:52, Richard Damon wrote: > > On 12/29/19 3:13 PM, Andrew Barnert via Python-ideas wrote: >>> On Dec 29, 2019, at 10:57, Abdur-Rahmaan Janhangeer >>> wrote: >>> >>>> On Sun, Dec 29, 2019 at 10:45 PM Antoine Rozo >>>

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

2019-12-29 Thread Andrew Barnert via Python-ideas
t is for the sake of making sense of computer programs. (In the case of uint16, that actually does form a useful structure on its own if you consider them as Z/65536Z, but maybe it’s still worth considering them as an approximation of N instead.) ___ Py

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

2019-12-29 Thread Andrew Barnert via Python-ideas
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 closely approximates—in a well-defined an

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

2019-12-29 Thread Andrew Barnert via Python-ideas
the first NaN that way than by doing an extra pass, if it’s simpler and slightly faster for the non-exceptional case? ___ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.py

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

2019-12-29 Thread Andrew Barnert via Python-ideas
l kinds of places. Likewise, it’s even easier to write ignore-nan yourself than to write the DSU yourself: median = statistics.median(x for x in xs if not x.isnan()) … and yet this whole proposal is still useful, isn’t it? So, why isn’t adding a key parameter (as well as an on_nan that take

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

2019-12-29 Thread Andrew Barnert via Python-ideas
at’s a lot less obvious and a lot more useful. And the same is true for IEEE binary64. You can say they’re not numbers, or that they are, or that some of them are and some of them aren’t, but they’re not the rationals (or the reals or the affinely extended reals or a subalgebra of any of the a

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

2019-12-29 Thread Andrew Barnert via Python-ideas
actually needs a key function because you can >> always decorate-sort-undecorate. And yet, key functions are useful in all >> kinds of places. > > > It's a balance, I think. `key_fn=` feels much too "heavy" for users of > statistics module. Key functions are

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

2019-12-29 Thread Andrew Barnert via Python-ideas
hich one of those intuitions was wrong? Neither; they’re both right, and therefore we just found a new way to distinguish between two useful classes of “number” structures. We’re farther from ever from knowing which things are “really numbers”, but who cares? _______

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

2019-12-29 Thread Andrew Barnert via Python-ideas
pecify it explicitly.) _______ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/arch

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

2019-12-29 Thread Andrew Barnert via Python-ideas
7;ve got "learned up" about this three times now :-). Given we > cannot control those bit patterns from Python, I'm a bit "meh"... but I get > the rule (yeah, yeah, struct module) That’s either me or AT&T being slow; either way, apologies. >> The 95%

[Python-ideas] Re: Total_order

2019-12-29 Thread Andrew Barnert via Python-ideas
harder to debug your code when you can’t inspect the values, but on the plus side you do feel really clever for a few seconds when you first get it working. :) _______ Python-ideas mailing list -- [email protected] To unsubscribe send an email to python

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

2019-12-30 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 23:50, Steven D'Aprano wrote: > > On Sun, Dec 29, 2019 at 06:23:03PM -0800, Andrew Barnert via Python-ideas > wrote: > >> Likewise, it’s even easier to write ignore-nan yourself than to write the >> DSU yourself: >> >>median

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

2019-12-30 Thread Andrew Barnert via Python-ideas
it explicitly.) > > But it DOESN'T make all positive NaNs equivalent, as they do not compare > 'equal'. Neither is less than the other, but they don't compare equal. If you > use a sort function (not the one that Python currently uses) that uses an > equalit

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

2019-12-30 Thread Andrew Barnert via Python-ideas
> On Dec 30, 2019, at 08:55, David Mertz wrote: >> Presumably the end user (unlike the statistics module) knows what data they >> have. > > No, Steven is right here. In Python we might very sensibly mix numeric > datatypes. The statistics module explicitly doesn’t

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

2019-12-30 Thread Andrew Barnert via Python-ideas
> On Dec 30, 2019, at 14:05, Richard Damon wrote: > > On 12/30/19 4:22 PM, Andrew Barnert via Python-ideas wrote: >>> On Dec 30, 2019, at 06:50, Richard Damon wrote: >>> On 12/30/19 12:06 AM, Andrew Barnert wrote: >>>>> On Dec 29, 2019, at 20

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

2019-12-30 Thread Andrew Barnert via Python-ideas
2 elements before sorting, and, given IGNORE (and POISON?) they probably need to instead check for that after the filter-and-sort step. (Presumably asking for the xtile of [nan, nan, nan] with IGNORE is an error, not nan.) ___ Python-ideas mailing list -- python-ideas@pyth

[Python-ideas] Re: Philosophy of floating-point (was Fix statistics.median())

2019-12-30 Thread Andrew Barnert via Python-ideas
by the exponent times the sign, which handles both -0<0 and more vs. less subnormal representations of equal finite values. While we’re at it, IIRC, it specifically mandates a<=b rather than a___ Python-ideas mailing list -- [email protected] To u

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Andrew Barnert via Python-ideas
of anything obvious that makes sense. > To do this any and all could make a specially tagged tupl which interacts > with operators like 'in' in a special way where it applies each of its > members and or/ands the results. > > It may even be possible to do this with the ex

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Andrew Barnert via Python-ideas
o translate that repeated check to a set operation. ___________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.pytho

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Andrew Barnert via Python-ideas
t; > if foobar is foo or bar or baz: > pass > > now the recommended syntax translate to this: (I think so) > > if foo (IS NOT '0' or None or empty) or bar (IS NOT '0' or None or empty) or > baz in foobar I’m not sure what this translation is supposed

[Python-ideas] Re: Allow metaclass to override __subclasscheck__ for metaclass relations

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 09:43, Soni L. wrote: > > I would like this code to work, but currently python ignores > __subclasscheck__ in many places where it checks for subclasses: > > class MM(type): > def __subclasscheck__(self, subclass): > return issu

[Python-ideas] Re: Allow metaclass to override __subclasscheck__ for metaclass relations

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 11:02, Soni L. wrote: > > >> On 2019-12-31 3:56 p.m., Andrew Barnert wrote: >> On Dec 31, 2019, at 09:43, Soni L. wrote: >> > > I would like this code to work, but currently python ignores >> > > __subclasscheck__ in

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 11:50, MRAB wrote: > > On 2019-12-31 17:49, Andrew Barnert via Python-ideas wrote: >>> On Dec 31, 2019, at 08:03, Richard Damon wrote: >>> IF I were to change the syntax ( which I don't propose), I believe the >>> construct like f

[Python-ideas] Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
Every so often, someone suggests that Python should have a pattern matching case statement like Scala, C#, Swift, Haskell, etc. Or they just suggest that “Python needs algebraic data types” but end up concluding that the biggest part Python is missing is not the types themselves, but a

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
case SMS(number, message) => notify(s"You got an SMS from $number! Message: $message") case VoiceRecording(name, link) => notify(s"You received a Voice Recording from $name! Click the link to hear it: $link") } } Here it i

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 14:58, Soni L. wrote: > > >> On 2019-12-31 7:28 p.m., Andrew Barnert via Python-ideas wrote: >> >> The second is an “if try” statement, which tries an expression and runs the >> body if that doesn’t raise (instead of if it’s truthy), but j

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 15:52, Greg Ewing wrote: > > On 1/01/20 11:28 am, Andrew Barnert via Python-ideas wrote: > >> The first is to extend unpacking assignment to target-or-expression lists. >> Like this: >>x, 0, z = vec >> But >> it doesn’t bind anyt

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 17:54, David Mertz wrote: > >  >> On Tue, Dec 31, 2019 at 8:23 PM Andrew Barnert via Python-ideas >> wrote: > >> > K = 42 >> > x, K, z = vec >> Yes. I’m surveying the way other languages deal with this to try to figure &

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
rejected on that basis. (Which I think is a serious possibility. Something about if-try still smells weird to me in a way I haven’t figured out yet.) _______ Python-ideas mailing list -- [email protected] To unsubscribe send an email to python-ideas-le...

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Andrew Barnert via Python-ideas
you could leverage if/elif chains (essentially the same way Python covers 90% of what C switch can do without needing a new structure) and tuple unpacking. Now it seems much more feasible. (Also, dataclass is close enough to a “case class”—and provides a model for building them manually—that the pr

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Andrew Barnert via Python-ideas
>> On Jan 1, 2020, at 04:21, Steven D'Aprano wrote: >> >> On Tue, Dec 31, 2019 at 05:18:59PM -0800, Andrew Barnert via Python-ideas >> wrote: >> >> Some languages use special syntax to mark either values or targets: >> let x, K, let z = vec >

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Andrew Barnert via Python-ideas
On Jan 1, 2020, at 07:03, Steven D'Aprano wrote: > > On Tue, Dec 31, 2019 at 02:28:26PM -0800, Andrew Barnert via Python-ideas > wrote: > >>if try 0, y, z := vec: >># do yz plane stuff >>elif try x, 0, z := vec: >># do xz

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Andrew Barnert via Python-ideas
> On Jan 1, 2020, at 08:32, Guido van Rossum wrote: >  > Here's a proposal for JavaScript that seems to be going through > standardization: https://github.com/tc39/proposal-pattern-matching The JS solution is interesting, but I’m not sure how well it works for a different la

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Andrew Barnert via Python-ideas
g case, or the try-expression PEP is up for reconsideration and incompatible with it, etc., that’s *not* fine; anything I build that requires “if try” will not be acceptable, so it’s not worth exploring further. _______ Python-ideas mailing list -- python-i

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-02 Thread Andrew Barnert via Python-ideas
is kind of backward from the way most other languages do things, but it might work. After all, an as clause is already effectively a backward assignment, and it reads nicely. > Consider something like > if (x, y, z) := vec as ?, 0, ?: # if y == 0 Even though the ? makes sense there, it doesn’

<    4   5   6   7   8   9   10   11   12   13   >