[Python-ideas] Re: itertools.compress default selectors

2021-09-22 Thread ml
Then may be we could enhance "filter" or introduce some alias? Why we have "filterfalse" and don't have "filtertrue"?Thanks!Stepan Dyatkovskiy 14.09.2021, 22:20, "Chris Angelico" :On Wed, Sep 15, 2021 at 4:58 AM Tim Peters wrote: Or perhaps the `compress()` implementation cou

[Python-ideas] Re: itertools.compress default selectors

2021-09-14 Thread Chris Angelico
On Wed, Sep 15, 2021 at 4:58 AM Tim Peters wrote: > Or perhaps the `compress()` implementation could grow internal > conditionals to use a different algorithm if the second argument is > omitted. But that would be a major change to support something that's > already easily done in more than one mo

[Python-ideas] Re: itertools.compress default selectors

2021-09-14 Thread Paul Moore
On Tue, 14 Sept 2021 at 19:58, Tim Peters wrote: > Except it's not that simple: Apologies, Tim, it took me a couple of reads to work out what you were saying here. I hope you won't mind if I restate the point for the benefit of anyone else who might have got confused it like I did... > def

[Python-ideas] Re: itertools.compress default selectors

2021-09-14 Thread Tim Peters
[Chris Angelico ] > ... > For it to be accepted, you have to convince people - particularly, > core devs - that it's of value. At the moment, I'm unconvinced, but on > the other hand, all you're proposing is a default value for a > currently-mandatory argument, so the bar isn't TOO high (it's not l

[Python-ideas] Re: itertools.compress default selectors

2021-09-14 Thread Chris Angelico
On Wed, Sep 15, 2021 at 4:03 AM m...@dyatkovskiy.com wrote: > > > The signature is wrong. > Thanks for remark. Of course proper signature would be: > > def jin(a: Iterable[Optional[str]], sep=“ “): > # … > > > Why do you (ab)use compress for that? > Well, it seems that it is subjective. To me

[Python-ideas] Re: itertools.compress default selectors

2021-09-14 Thread m...@dyatkovskiy.com
> The signature is wrong. Thanks for remark. Of course proper signature would be: def jin(a: Iterable[Optional[str]], sep=“ “): # … > Why do you (ab)use compress for that? Well, it seems that it is subjective. To me “[None, x, y, z]” -> “[x, y, z]” looks like “compression”. But if community

[Python-ideas] Re: itertools.compress default selectors

2021-09-14 Thread Steven D'Aprano
On Tue, Sep 14, 2021 at 11:31:43AM +0400, m...@dyatkovskiy.com wrote: > Thus I have collection of options and some of them are empty or None. > In order to get rendered command line options string I use “compress” > in conjunction with “join": > > >>> opts = " ".join(compress(flags, flags)) Wh

[Python-ideas] Re: itertools.compress default selectors

2021-09-14 Thread Paul Moore
On Tue, 14 Sept 2021 at 08:38, m...@dyatkovskiy.com wrote: > Main motivation was a use case where we gather command line options, and some > of them are… optional. [...] > And yet I’m solid that we need some compact and nice way for rendering > strings with command options. That would be a thin

[Python-ideas] Re: itertools.compress default selectors

2021-09-14 Thread m...@dyatkovskiy.com
OK, If I might tell some story... :) Main motivation was a use case where we gather command line options, and some of them are… optional. Below is a realistic example. Namely options for LLVM Clang: >>> flags = [“-O3”, “-fomit-frame-pointer”, maybe_pgo(context)] Here “maybe_pgo” returns either

[Python-ideas] Re: itertools.compress default selectors

2021-09-13 Thread Tim Peters
FYI, itertools.compress() is very useful in conjunction with itertools.cycle() to pick out elements following a periodic pattern of indices. For example, # Elements at even indices. >>> list(compress(range(20), cycle([1, 0]))) [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] # Or at odd ones. >>> list(compres

[Python-ideas] Re: itertools.compress default selectors

2021-09-13 Thread David Mertz, Ph.D.
I've never used compress() either. But I probably HAVE selected only the "truthy" elements of an iterable. The obvious way to do that is: it = (x for x in it if x) It feels like changing compress() would just be more obscure, but not add to clarity. On Mon, Sep 13, 2021, 5:07 PM Rob Cliffe via P

[Python-ideas] Re: itertools.compress default selectors

2021-09-13 Thread Rob Cliffe via Python-ideas
My 2c: I don't remember ever seeing itertools.compress (although I've occasionally browsed through itertools), and I've certainly never used it.  However, having worked out what it does, my first reaction was that this would be a harmless and mildly convenient change.  But might it not lead to

[Python-ideas] Re: itertools.compress default selectors

2021-09-13 Thread Paul Moore
You can already do this using filter(None, a) >>> list(filter(None, [None, "", "-filove-python", "CFLAGS=-O3"])) ['-filove-python', 'CFLAGS=-O3'] There's arguably a minor readability improvement (compress(a) suggests "remove the unneeded elements") but I'm not sure that's enough to justi