|
|
|
|
|
by JimDabell
1060 days ago
|
|
You wouldn’t really write it as you have in the second example though. The Pythonic way of writing something like this is to use list comprehensions or generator expressions, for example: min(some_op(item) for item in bar.baz() if some_filter(item)).foo()
Or decomposed a little for clarity: processed_items = (some_op(item) for item in bar.baz() if some_filter(item))
min(processed_items).foo()
This is pretty readable – a natural language description of the first line is “do some_op for each item in bar.baz that matches some_filter”, which corresponds 1:1 with the code. |
|
The chaining example in OP’s first example is way better