What do we gain from this? Three characters.
I'm not sure how useful this would be. On Mon, Jun 28, 2021, 9:29 PM David Mertz <me...@gnosis.cx> wrote: > Umm?! > > items = (j for j in range(10) if j not in {2, 8}) > > We don't need a new keyword. Nor a tortured use of an old one. > > On Mon, Jun 28, 2021, 8:46 PM Rob Cliffe via Python-ideas < > python-ideas@python.org> wrote: > >> Another wild idea: Suppose that after a line that introduces a suite, >> including the final colon, you could write further lines on the same >> physical line, and this would be semantically equivalent to having them >> on separate lines with increasing indents, but a smaller indent than the >> following lines in the suite body. Example: >> >> with open('file1') as f: with open('file2') as g: >> <do stuff> >> >> Then you could write: >> >> for i in range(0, 10): if i not in range(2, 8): >> <do stuff> >> # This is arguably slightly easier to read than having two separate >> lines, as it puts both aspects of a single concept ("what values of i do >> I loop over?") together. It also avoids a physical indentation level. >> >> Rob Cliffe >> >> On 29/06/2021 00:44, Richard Damon wrote: >> > On 6/28/21 5:40 PM, Max Shouman wrote: >> >> This is more of a syntactic sugar than an actual new feature, but... >> >> Exactly, 'but' is the idea: a special keyword to be used in for >> statements to exclude values from the iterable. >> >> >> >> E.g., when iterating over a generator: >> >>>>> for i in range(0, 10) but (2, 8): >> >> would implicitly create a new generator comprehensively, as in: >> >>>>> for i in (j for j in range(0, 10) if j not in [2, 8]): >> >> It might not add such a feature to justify the definition of a >> but_stmt in python.gram, but it's fully compliant with Python's philosophy >> of concise, clear and elegant code. >> >> >> >> #road to a programming natural language (jk) >> > Wild idea, but could we avoid a new keyword by reusing one that can't go >> > there, like except? >> > >> > >> > for i in range(0,10) except (2, 8): >> > >> > >> > don't know if it is actually worth it, but at least it doesn't add a new >> > keyword. >> > >> >> _______________________________________________ >> 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/RFD3U3HKCWLRKSRZUEQF5IL3F65S66LD/ >> 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/TNEUSZWVEE4KJZORSFHUANUXHMJSPOVK/ > 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/2OOSCPBNTN2XUHGBTBMEJOALV4ZWRGJC/ Code of Conduct: http://python.org/psf/codeofconduct/