4 ms·
This works for conditionals: In [4]: f = lambda x: "Yes" if x else "No" In [5]: f(True) Out[5]: 'Yes' In [6]: f(False) Out[6]: 'No' It's
by diarrhea 6y ago
This works for conditionals:
In [4]: f = lambda x: "Yes" if x else "No"
In [5]: f(True)
Out[5]: 'Yes'
In [6]: f(False)
Out[6]: 'No'
It's Python's version of ternary operators, so not sure if that counts as a "true" conditional; but it is one.
Loops don't work, but list comprehensions do, and they are definitely the way to go here. Multi-line loops deserve a `def`.