|
|
|
|
|
by gorgoiler
1057 days ago
|
|
Your point about ordering and readability really rang true for me. My way around this in Python is to separate the map and the reduce: do the map in one part with a list comprehension and the reduce in a second part on a new line. I’ll wrap the whole thing in a named function as a way of describing what I’m doing and make it a closure if it’s used only once: def f(bar):
def smallest_baz():
bazs = (
some_op(b)
for b in bar.baz()
if some_filter(b)
)
return min(bazs)
return smallest_baz().foo()
|
|