4 ms·
That version (and the one in the article) are somewhat confusing to parse and detract from the point of the article. This seems more "Pythonic": def looku
by wylee 12y ago
That version (and the one in the article) are somewhat confusing to parse and detract from the point of the article.
This seems more "Pythonic":
def lookup(d, key):
return Just(d[key]) if key in d else None
def values_in(keys, d):
values = []
for k in keys:
x = lookup(d, k)
if x:
values.append(x.value)
return values
If you really want a one-liner, I think this is easier to understand:
def values_in(keys, d):
return [x.value for x in (lookup(d, k) for k in keys) if x]