|
|
|
|
|
by diarrhea
1982 days 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`. |
|