These examples would seem to be tailor-made for the walrus operator:
On 15/06/2020 16:01, M Bfmv 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: []
if (this := [i for i in range(10) if i == 11]):
    print(this)
```

Another one
```
if [i for i in range(10) if i == 5]:
    print(this)

Evaluate: [5]
if (this := [i for i in range(10) if i == 5]):
    print(this)
```
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 -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/PB7AHBHELBLRFVKRRQL4M3SNWB4RXGNW/
Code of Conduct: http://python.org/psf/codeofconduct/

_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/HKRX73KWADMF6BPTV7SR2JTIK6J6K733/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to