How about using the Walrus operator/assignment expression, since Python 3.8? if this := [i for i in range(10) if i == 5]: print(this) Evaluate: [5] On Mon, 15 Jun 2020 at 16:03, M Bfmv <ik951m@live.nl> wrote:
Hey all. Ever had some list comprehension hell in your code? Me neither *whistles 418 happly*...
I was thinking about this idea and while `this` keyword is equalevant to `self` i have to explain myself. English is not my main language, sorry for that :' ) Here is my pseudo code.
``` if [i for i in range(10) if i == 11]: print(this)
Evaluate: [] ```
Another one ``` if [i for i in range(10) if i == 5]: print(this)
Evaluate: [5] ``` As I try to show above. It would be neat to make a list comprhension if statement and use those results in the if condition as the `this` parameter Instead of declaring variables like
``` a = [i for i in range(10) if i == 5] if a: print(a)
Evaluate: [5] ```
I hope I explained my idea well enough and hope to see something like this in the future. If anyone has questions on my interpretation please ask.
_______________________________________________ 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/PB7AHB... Code of Conduct: http://python.org/psf/codeofconduct/