>   print([
>      3,
>      if False never_called() unless False,
>      if False never_called() unless False,
>      2,
>      if True 5 unless False,
>      4
>    ]) # => [3, 2, 5, 4]

Do you mean this ?Currently what I use is the `*` operator on lists :

```
print([
    3,
]
+ ([never_called()] if False else [])
+ [
    2,
]
+ ([5] if True else [])
+ [
    4
]) # => [3, 2, 5, 4]
```
(put the whitespaces where you want)

And if the call to `never_called()` is not important (no need for
shortcircuit) :

```
print([
    3,
]+ [
   never_called()
] * False + [
    2,
] + [
   5
] * True + [
    4
]) # => [3, 2, 5, 4]
```
(put the whitespaces where you want)

You could do things like L = [4,5,2] + ['hello', world'] * (a == 5) + [8,9]

Of course, that's not as optimised as :
L = []
L += [4,5,2]
if a == 5: L += ['hello', world']
L += [8,9]
_______________________________________________
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/4YJ3EXF77KFD3ZMJMNWM33CKE7KE7JU2/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to