
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 justify the change. On the other hand, it's not like there's any obviously better default value for the second argument... I guess overall I'm fairly indifferent to the change. Paul On Mon, 13 Sept 2021 at 13:07, <ml@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-leave@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/LVD63O... Code of Conduct: http://python.org/psf/codeofconduct/