On Fri, Jul 26, 2019 at 6:57 AM Eli Berkowitz <eliberkow...@gmail.com> wrote:
> By #1 "should" be a 1-liner, I mean that I think a reasonable goal is to > have a good syntax for this operation to be one line. > > And for #3 I'm basing it also off Pep 8: "Compound statements (multiple > statements on the same line) are generally discouraged." > > Given that the proposed alternative isn't currently valid and #1 isn't > 'bad' in any way other than being an extra line, I can understand not > wanting to move this forward. > > One last thing to consider is how this would work with filtering: > ``` > f(item) for item in lst if g(item) > ``` > saves even more space, as the #1 alternative would be > Do understand that Python also strives for explicitness on top of clarity which suggests trying to compress logic for the sake of saving a line or two isn't a goal if it doesn't help readability. I do get the desire for having an easy way to exhaust an iterator, but even with your desire for a generator expression syntax, you can still make it short with: ``` for _ in (f(item) for item in lst if g(item)): pass ``` That doesn't require any new syntax (which is a very "expensive" thing to do in Python as you have to update books for that sort of thing). -Brett ``` > for item in lst: > if g(item): > f(item) > ``` > However this advantage doesn't apply to if/else as the syntax becomes > ambiguous: > ``` > f(item) for item in lst if g else h > # could mean: > [f(item) for item in lst] if g else h > # or > [f(item) for item in lst if g else h] > ``` > _______________________________________________ > 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/BSALZNYSBZRUDDIFXRHFXGQ3B4V64ZFQ/ > 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/F77N4HEANGAHG62KBGKKBMS2Q7DNR5WY/ Code of Conduct: http://python.org/psf/codeofconduct/