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 Python-ideas <
python-ideas@python.org> wrote:

> 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 bugs if the second argument were accidentally omitted?
> Best wishes
> Rob Cliffe
>
> On 13/09/2021 12:07, m...@dyatkovskiy.com wrote:
> > Hi!
> >
> > I propose to enhance "itertools.compress" in such a way so if you don't
> provide selectors, then "data" itself is used as a selectors.
> > So "compress(a)" would be equivalent to "compress(a, a)"
> >
> > For example:
> >
> >>>> from itertools import compress
> >
> >>>> [*compress([0, 1, 2, 3]))]
> > [1, 2, 3]
> >
> >>>> [*compress(["", "CFLAGS=-O3"])]
> > ["CFLAGS=-O3"]
> >
> >>>> opts = compress([None, "", "-filove-python",  "CFLAGS=-O3"])
> >>>> " ".join(opts)
> > '-filove-python CFLAGS=-O3'
> >
> > What do you think guys about this? Perhaps it was proposed by someone
> else?
> >
> > Thanks!
> > Stepan Dyatkovskiy
> > _______________________________________________
> > Python-ideas mailing list -- python-ideas@python.org
> > To unsubscribe send an email to python-ideas-le...@python.org
> > https://mail.python.org/mailman3/lists/python-ideas.python.org/
> > Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/LVD63OEWRTTU542NKFODLERXCM7LEQ5D/
> > Code of Conduct: http://python.org/psf/codeofconduct/
>
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/433A57HX3XICLCX2TT4M3G5AL34OWOA2/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ZQRB5LFDCWIE2PQB52NY7M6F7ZCC5K2E/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to