Most pythonic callable generating True?
We could use partial
as an alternative to lambda
:
from functools import partial
from collections import defaultdict
d_true = defaultdict(partial(bool, True))
print(d_true['bona fide'])
(Which is also Python 2 friendly.)
Well, you can do
d = defaultdict(True.__bool__)
but I personally would go with the lambda: True
.